1 .- Introducción

2 .- Limpieza y preparación entorno trabajo

# Limpiamos el entorno de Trabajo
rm(list=ls())

# Limpiamos la consola
cat("\014")
# Comprobamos que está bien establecido el directorio
getwd()
## [1] "/home/oscar/Documentos/R/menstrual"
dir()
##  [1] "data.csv"                "header.html"            
##  [3] "mcb_separado.csv"        "mcb_separado.xls"       
##  [5] "mcbackup_files"          "mcbackup.csv"           
##  [7] "mcbackup.html"           "mcbackup.json"          
##  [9] "mcbackup.Rmd"            "menstrual-jupyter.ipynb"
## [11] "menstrual.ipynb"         "Untitled.ipynb"         
## [13] "Untitled1.ipynb"         "Untitled2.ipynb"
#indicamos el directorio de trabajo
setwd("~/Documentos/R/menstrual")

2.1 .- Carga de librerias

# Importamos las librerias a utilizar

packages <- c( "magrittr", "jsonlite", "tidyverse", "prettyR", "git2r","funModeling", "zoo", "lubridate", "GGally", "ggfortify", "ggplot2", "modeest")
newpack  = packages[!(packages %in% installed.packages()[,"Package"])]

if(length(newpack)) install.packages(newpack)
a=lapply(packages, library, character.only=TRUE)

2.2 .- Lectura JSON

library(rjson)

# You can pass directly the filename
my.JSON <- fromJSON(file="mcbackup.json")

Genero las listas de cada elemento

settings <- my.JSON$settings
event <- my.JSON$event
measure <- data.frame(my.JSON$measure)
notification<- data.frame(my.JSON$notification)
symptom<- data.frame(my.JSON$symptom)
day <- data.frame(my.JSON$day)
value <- data.frame(my.JSON$value)

Genero cada dataframe

json_file_settings <- lapply(my.JSON$settings, function(x) {
  x[sapply(x, is.null)] <- NA
  unlist(x)
})
settings <-as.data.frame(t(do.call("cbind", json_file_settings)))
json_file_day <- lapply(my.JSON$day, function(x) {
  x[sapply(x, is.null)] <- NA
  unlist(x)
})
day <-as.data.frame(t(do.call("cbind", json_file_day)))
json_file_value <- lapply(my.JSON$value, function(x) {
  x[sapply(x, is.null)] <- NA
  unlist(x)
})
value <-as.data.frame(t(do.call("cbind", json_file_value)))
json_file_symptom <- lapply(my.JSON$symptom, function(x) {
  x[sapply(x, is.null)] <- NA
  unlist(x)
})
symptom <-as.data.frame(t(do.call("cbind", json_file_symptom)))
json_file_notification <- lapply(my.JSON$notification, function(x) {
  x[sapply(x, is.null)] <- NA
  unlist(x)
})
notification <- as.data.frame(t(do.call("cbind", json_file_notification)))
json_file_event <- lapply(my.JSON$event, function(x) {
  x[sapply(x, is.null)] <- NA
  unlist(x)
})
event <-as.data.frame(t(do.call("cbind", json_file_event)))
json_file_measure <- lapply(my.JSON$measure, function(x) {
  x[sapply(x, is.null)] <- NA
  unlist(x)
})
measure <-as.data.frame(t(do.call("cbind", json_file_measure)))

Eliminamos objetos innecesarioss

rm(json_file_day,json_file_event,json_file_measure,json_file_notification,json_file_symptom,json_file_value,a,my.JSON,json_file_settings)

Cambiamos el nombre del id

simptoma <- symptom %>% 
  rename(symptom_id = id)
valor <- value %>%
  rename(value_id = id)

Fusionamos 2 tablas

evento <- left_join(event, valor, by = "value_id")
measures <- merge(simptoma, measure, by = "symptom_id", all = TRUE)
data_raw1 <- merge(measures, evento, by= "symptom_id", all = TRUE)
rm(symptom,simptoma,value,valor,measures,measure,settings)
data_raw2 <- merge(data_raw1, notification, by = "symptom_id", all = TRUE)
rm(event,notification,evento,setting,data_raw1)
data_raw <- merge(data_raw2,day, by= "date", all = TRUE)
rm(day, data_raw2, settings)

3 .-EDA - Exloración y análisis de datos

EDA_basico <- function(data)
{
  str(data)
  dim(data)
  colnames(data) 
  summary(data)
  # describe(data) #library(prettyR)
}

3.1 .-Resumen DATA-RAW

EDA_basico(data_raw)
## 'data.frame':    855 obs. of  26 variables:
##  $ date      : chr  "2012-09-09" "2013-05-17" "2013-05-29" "2013-05-31" ...
##  $ symptom_id: chr  "bdd8fb86-4cbf-4832-b975-742cd3109215" "c8c60842-b805-41ba-b7b9-d772e39ff3b5" "0239f552-c6b3-42ff-8005-0d45ea1f8962" "c8c60842-b805-41ba-b7b9-d772e39ff3b5" ...
##  $ name.x    : chr  "Menstruación" "Citas médicas" "Relación sexual" "Citas médicas" ...
##  $ num.x     : chr  "-9999" "14" "0" "14" ...
##  $ mode      : chr  "0" "0" "0" "0" ...
##  $ type      : chr  "1" "1" "4" "1" ...
##  $ layout    : chr  "3" "7" "2" "7" ...
##  $ chart     : chr  "1" "0" "0" "0" ...
##  $ category  : chr  "0" "c8c60842-b805-41ba-b7b9-d772e39ff3b5" "0239f552-c6b3-42ff-8005-0d45ea1f8962" "c8c60842-b805-41ba-b7b9-d772e39ff3b5" ...
##  $ id.x      : chr  NA NA NA NA ...
##  $ datetime  : chr  NA NA NA NA ...
##  $ value     : chr  NA NA NA NA ...
##  $ value_id  : chr  "23d86cea-d536-4343-ab59-a1bb86aec86e" "cc56c587-77d5-489e-a650-f7814c6f30b0" "b3128bcd-b057-4de1-b776-147dc6edb677" "cc56c587-77d5-489e-a650-f7814c6f30b0" ...
##  $ deleted   : chr  "2012-09-09" "2013-05-17" "2013-05-29" "2013-05-31" ...
##  $ name.y    : chr  "Moderada" "Obstetricia y Ginecología" "Sin protección" "Obstetricia y Ginecología" ...
##  $ num.y     : chr  "1" "1" "0" "1" ...
##  $ icon      : chr  "-2" "21" "32" "21" ...
##  $ color     : chr  "-65536" "-1" "-65536" "-1" ...
##  $ id.y      : chr  NA NA NA NA ...
##  $ label     : chr  NA NA NA NA ...
##  $ hour      : chr  NA NA NA NA ...
##  $ minute    : chr  NA NA NA NA ...
##  $ when      : chr  NA NA NA NA ...
##  $ delay     : chr  NA NA NA NA ...
##  $ active    : chr  NA NA NA NA ...
##  $ note      : chr  NA NA NA NA ...
##      date            symptom_id           name.x             num.x          
##  Length:855         Length:855         Length:855         Length:855        
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##      mode               type              layout             chart          
##  Length:855         Length:855         Length:855         Length:855        
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##    category             id.x             datetime            value          
##  Length:855         Length:855         Length:855         Length:855        
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##    value_id           deleted             name.y             num.y          
##  Length:855         Length:855         Length:855         Length:855        
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##      icon              color               id.y              label          
##  Length:855         Length:855         Length:855         Length:855        
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##      hour              minute              when              delay          
##  Length:855         Length:855         Length:855         Length:855        
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##     active              note          
##  Length:855         Length:855        
##  Class :character   Class :character  
##  Mode  :character   Mode  :character
# Valores vacíos
print("Mostrar variables con campos na")
## [1] "Mostrar variables con campos na"
colSums(is.na(data_raw))
##       date symptom_id     name.x      num.x       mode       type     layout 
##        132         18         19         19         19         19         19 
##      chart   category       id.x   datetime      value   value_id    deleted 
##         19         19        738        738        738        150        150 
##     name.y      num.y       icon      color       id.y      label       hour 
##        150        150        150        150        852        852        852 
##     minute       when      delay     active       note 
##        852        852        852        852        790
print("Mostrar variables con datos vacios")
## [1] "Mostrar variables con datos vacios"
colSums(data_raw=="")
##       date symptom_id     name.x      num.x       mode       type     layout 
##         NA         NA         NA         NA         NA         NA         NA 
##      chart   category       id.x   datetime      value   value_id    deleted 
##         NA         NA         NA         NA         NA         NA         NA 
##     name.y      num.y       icon      color       id.y      label       hour 
##         NA         NA         NA         NA         NA         NA         NA 
##     minute       when      delay     active       note 
##         NA         NA         NA         NA         NA
print("Valores con integrogación")
## [1] "Valores con integrogación"
colSums(data_raw==" ?")
##       date symptom_id     name.x      num.x       mode       type     layout 
##         NA         NA         NA         NA         NA         NA         NA 
##      chart   category       id.x   datetime      value   value_id    deleted 
##         NA         NA         NA         NA         NA         NA         NA 
##     name.y      num.y       icon      color       id.y      label       hour 
##         NA         NA         NA         NA         NA         NA         NA 
##     minute       when      delay     active       note 
##         NA         NA         NA         NA         NA
#print("Mostrar variables con campos na")
#which (is.na(data_raw))
print("Es cierto que hay valores  na?")
## [1] "Es cierto que hay valores  na?"
any(is.na(data_raw))
## [1] TRUE
print("Suma valores na")
## [1] "Suma valores na"
sum(is.na(data_raw))
## [1] 10151
data <- dplyr::select(data_raw, -id.y, -label, -hour, -minute, -when, -delay, -active, -note, -deleted)

4 Resumen data-frame

aed_basico <- function(data)
{
  glimpse(data)
  status(data) #library(git2r)
  head(freq(data))
  profiling_num(as.numeric(data))
  plot_num(data)
  describe(data)
  dim(data)
  summary(data)
  colnames(data)
}
#aed_basico((data))
glimpse(data)
## Rows: 855
## Columns: 17
## $ date       <chr> "2012-09-09", "2013-05-17", "2013-05-29", "2013-05-31", "2…
## $ symptom_id <chr> "bdd8fb86-4cbf-4832-b975-742cd3109215", "c8c60842-b805-41b…
## $ name.x     <chr> "Menstruación", "Citas médicas", "Relación sexual", "Citas…
## $ num.x      <chr> "-9999", "14", "0", "14", "0", "0", "14", "0", "14", "0", …
## $ mode       <chr> "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"…
## $ type       <chr> "1", "1", "4", "1", "4", "4", "1", "4", "1", "4", "4", "1"…
## $ layout     <chr> "3", "7", "2", "7", "2", "2", "7", "2", "7", "2", "2", "3"…
## $ chart      <chr> "1", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "1"…
## $ category   <chr> "0", "c8c60842-b805-41ba-b7b9-d772e39ff3b5", "0239f552-c6b…
## $ id.x       <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
## $ datetime   <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
## $ value      <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
## $ value_id   <chr> "23d86cea-d536-4343-ab59-a1bb86aec86e", "cc56c587-77d5-489…
## $ name.y     <chr> "Moderada", "Obstetricia y Ginecología", "Sin protección",…
## $ num.y      <chr> "1", "1", "0", "1", "0", "0", "1", "0", "1", "1", "1", "0"…
## $ icon       <chr> "-2", "21", "32", "21", "32", "32", "21", "32", "21", "32"…
## $ color      <chr> "-65536", "-1", "-65536", "-1", "-65536", "-65536", "-1", …
status(data) #library(git2r)
##      variable q_zeros     p_zeros q_na       p_na q_inf p_inf      type unique
## 1        date       0 0.000000000  132 0.15438596     0     0 character    635
## 2  symptom_id       1 0.001169591   18 0.02105263     0     0 character     28
## 3      name.x       0 0.000000000   19 0.02222222     0     0 character     27
## 4       num.x     308 0.360233918   19 0.02222222     0     0 character     27
## 5        mode     719 0.840935673   19 0.02222222     0     0 character      2
## 6        type       0 0.000000000   19 0.02222222     0     0 character      9
## 7      layout     191 0.223391813   19 0.02222222     0     0 character     19
## 8       chart     432 0.505263158   19 0.02222222     0     0 character     22
## 9    category     182 0.212865497   19 0.02222222     0     0 character     27
## 10       id.x       0 0.000000000  738 0.86315789     0     0 character    117
## 11   datetime       0 0.000000000  738 0.86315789     0     0 character    117
## 12      value       0 0.000000000  738 0.86315789     0     0 character     62
## 13   value_id       0 0.000000000  150 0.17543860     0     0 character     25
## 14     name.y       0 0.000000000  150 0.17543860     0     0 character     18
## 15      num.y     402 0.470175439  150 0.17543860     0     0 character      5
## 16       icon       0 0.000000000  150 0.17543860     0     0 character      9
## 17      color       0 0.000000000  150 0.17543860     0     0 character      9
head(freq(data)) 
##           date frequency percentage cumulative_perc
## 1         <NA>       132      15.44           15.44
## 2   2014-10-29         3       0.35           15.79
## 3   2014-12-28         3       0.35           16.14
## 4   2015-01-14         3       0.35           16.49
## 5   2015-05-05         3       0.35           16.84
## 6   2016-02-10         3       0.35           17.19
## 7   2017-12-20         3       0.35           17.54
## 8   2013-06-07         2       0.23           17.77
## 9   2013-08-17         2       0.23           18.00
## 10  2013-09-15         2       0.23           18.23
## 11  2014-09-20         2       0.23           18.46
## 12  2014-09-30         2       0.23           18.69
## 13  2014-10-13         2       0.23           18.92
## 14  2014-10-14         2       0.23           19.15
## 15  2014-10-15         2       0.23           19.38
## 16  2014-10-24         2       0.23           19.61
## 17  2014-10-25         2       0.23           19.84
## 18  2014-10-26         2       0.23           20.07
## 19  2014-10-27         2       0.23           20.30
## 20  2014-10-31         2       0.23           20.53
## 21  2014-11-02         2       0.23           20.76
## 22  2014-11-15         2       0.23           20.99
## 23  2014-11-29         2       0.23           21.22
## 24  2014-12-07         2       0.23           21.45
## 25  2014-12-08         2       0.23           21.68
## 26  2014-12-09         2       0.23           21.91
## 27  2014-12-10         2       0.23           22.14
## 28  2014-12-13         2       0.23           22.37
## 29  2014-12-14         2       0.23           22.60
## 30  2014-12-17         2       0.23           22.83
## 31  2014-12-20         2       0.23           23.06
## 32  2014-12-22         2       0.23           23.29
## 33  2014-12-24         2       0.23           23.52
## 34  2014-12-26         2       0.23           23.75
## 35  2015-01-17         2       0.23           23.98
## 36  2015-01-19         2       0.23           24.21
## 37  2015-01-24         2       0.23           24.44
## 38  2015-01-27         2       0.23           24.67
## 39  2015-02-06         2       0.23           24.90
## 40  2015-02-08         2       0.23           25.13
## 41  2015-02-10         2       0.23           25.36
## 42  2015-02-11         2       0.23           25.59
## 43  2015-02-18         2       0.23           25.82
## 44  2015-02-20         2       0.23           26.05
## 45  2015-03-12         2       0.23           26.28
## 46  2015-03-18         2       0.23           26.51
## 47  2015-03-21         2       0.23           26.74
## 48  2015-03-23         2       0.23           26.97
## 49  2015-03-25         2       0.23           27.20
## 50  2015-03-27         2       0.23           27.43
## 51  2015-04-27         2       0.23           27.66
## 52  2015-04-28         2       0.23           27.89
## 53  2015-05-01         2       0.23           28.12
## 54  2015-05-02         2       0.23           28.35
## 55  2015-05-03         2       0.23           28.58
## 56  2015-05-31         2       0.23           28.81
## 57  2015-06-19         2       0.23           29.04
## 58  2015-07-23         2       0.23           29.27
## 59  2015-07-25         2       0.23           29.50
## 60  2015-07-27         2       0.23           29.73
## 61  2015-08-06         2       0.23           29.96
## 62  2015-08-25         2       0.23           30.19
## 63  2015-09-24         2       0.23           30.42
## 64  2015-12-13         2       0.23           30.65
## 65  2016-02-03         2       0.23           30.88
## 66  2016-02-07         2       0.23           31.11
## 67  2016-02-11         2       0.23           31.34
## 68  2016-02-23         2       0.23           31.57
## 69  2016-02-27         2       0.23           31.80
## 70  2016-03-01         2       0.23           32.03
## 71  2016-03-06         2       0.23           32.26
## 72  2016-05-12         2       0.23           32.49
## 73  2016-05-17         2       0.23           32.72
## 74  2016-07-26         2       0.23           32.95
## 75  2016-10-05         2       0.23           33.18
## 76  2016-12-02         2       0.23           33.41
## 77  2017-01-09         2       0.23           33.64
## 78  2017-12-18         2       0.23           33.87
## 79  2017-12-28         2       0.23           34.10
## 80  2018-04-07         2       0.23           34.33
## 81  2018-07-27         2       0.23           34.56
## 82  2019-08-19         2       0.23           34.79
## 83  2020-02-25         2       0.23           35.02
## 84  2012-09-09         1       0.12           35.14
## 85  2013-05-17         1       0.12           35.26
## 86  2013-05-29         1       0.12           35.38
## 87  2013-05-31         1       0.12           35.50
## 88  2013-06-05         1       0.12           35.62
## 89  2013-06-09         1       0.12           35.74
## 90  2013-06-10         1       0.12           35.86
## 91  2013-07-20         1       0.12           35.98
## 92  2013-07-24         1       0.12           36.10
## 93  2013-07-25         1       0.12           36.22
## 94  2013-07-31         1       0.12           36.34
## 95  2013-08-05         1       0.12           36.46
## 96  2013-08-16         1       0.12           36.58
## 97  2013-08-18         1       0.12           36.70
## 98  2013-08-19         1       0.12           36.82
## 99  2013-08-23         1       0.12           36.94
## 100 2013-08-25         1       0.12           37.06
## 101 2013-08-31         1       0.12           37.18
## 102 2013-09-10         1       0.12           37.30
## 103 2013-09-16         1       0.12           37.42
## 104 2013-09-17         1       0.12           37.54
## 105 2013-09-18         1       0.12           37.66
## 106 2013-09-20         1       0.12           37.78
## 107 2013-09-22         1       0.12           37.90
## 108 2013-10-01         1       0.12           38.02
## 109 2013-10-05         1       0.12           38.14
## 110 2013-10-06         1       0.12           38.26
## 111 2013-10-08         1       0.12           38.38
## 112 2014-07-01         1       0.12           38.50
## 113 2014-08-04         1       0.12           38.62
## 114 2014-08-05         1       0.12           38.74
## 115 2014-08-06         1       0.12           38.86
## 116 2014-09-07         1       0.12           38.98
## 117 2014-09-09         1       0.12           39.10
## 118 2014-09-11         1       0.12           39.22
## 119 2014-09-12         1       0.12           39.34
## 120 2014-09-13         1       0.12           39.46
## 121 2014-09-16         1       0.12           39.58
## 122 2014-09-17         1       0.12           39.70
## 123 2014-09-18         1       0.12           39.82
## 124 2014-09-19         1       0.12           39.94
## 125 2014-09-22         1       0.12           40.06
## 126 2014-09-24         1       0.12           40.18
## 127 2014-09-25         1       0.12           40.30
## 128 2014-09-26         1       0.12           40.42
## 129 2014-09-27         1       0.12           40.54
## 130 2014-09-28         1       0.12           40.66
## 131 2014-09-29         1       0.12           40.78
## 132 2014-10-02         1       0.12           40.90
## 133 2014-10-04         1       0.12           41.02
## 134 2014-10-06         1       0.12           41.14
## 135 2014-10-09         1       0.12           41.26
## 136 2014-10-10         1       0.12           41.38
## 137 2014-10-11         1       0.12           41.50
## 138 2014-10-12         1       0.12           41.62
## 139 2014-10-16         1       0.12           41.74
## 140 2014-10-17         1       0.12           41.86
## 141 2014-10-18         1       0.12           41.98
## 142 2014-10-19         1       0.12           42.10
## 143 2014-10-21         1       0.12           42.22
## 144 2014-10-28         1       0.12           42.34
## 145 2014-10-30         1       0.12           42.46
## 146 2014-11-01         1       0.12           42.58
## 147 2014-11-06         1       0.12           42.70
## 148 2014-11-07         1       0.12           42.82
## 149 2014-11-08         1       0.12           42.94
## 150 2014-11-10         1       0.12           43.06
## 151 2014-11-13         1       0.12           43.18
## 152 2014-11-17         1       0.12           43.30
## 153 2014-11-18         1       0.12           43.42
## 154 2014-11-22         1       0.12           43.54
## 155 2014-11-26         1       0.12           43.66
## 156 2014-12-04         1       0.12           43.78
## 157 2014-12-06         1       0.12           43.90
## 158 2014-12-11         1       0.12           44.02
## 159 2014-12-12         1       0.12           44.14
## 160 2014-12-15         1       0.12           44.26
## 161 2014-12-16         1       0.12           44.38
## 162 2014-12-18         1       0.12           44.50
## 163 2014-12-21         1       0.12           44.62
## 164 2014-12-23         1       0.12           44.74
## 165 2014-12-25         1       0.12           44.86
## 166 2014-12-27         1       0.12           44.98
## 167 2014-12-29         1       0.12           45.10
## 168 2014-12-30         1       0.12           45.22
## 169 2014-12-31         1       0.12           45.34
## 170 2015-01-01         1       0.12           45.46
## 171 2015-01-04         1       0.12           45.58
## 172 2015-01-05         1       0.12           45.70
## 173 2015-01-08         1       0.12           45.82
## 174 2015-01-10         1       0.12           45.94
## 175 2015-01-11         1       0.12           46.06
## 176 2015-01-12         1       0.12           46.18
## 177 2015-01-20         1       0.12           46.30
## 178 2015-01-22         1       0.12           46.42
## 179 2015-01-26         1       0.12           46.54
## 180 2015-01-28         1       0.12           46.66
## 181 2015-01-29         1       0.12           46.78
## 182 2015-01-30         1       0.12           46.90
## 183 2015-02-01         1       0.12           47.02
## 184 2015-02-02         1       0.12           47.14
## 185 2015-02-03         1       0.12           47.26
## 186 2015-02-04         1       0.12           47.38
## 187 2015-02-05         1       0.12           47.50
## 188 2015-02-07         1       0.12           47.62
## 189 2015-02-09         1       0.12           47.74
## 190 2015-02-13         1       0.12           47.86
## 191 2015-02-16         1       0.12           47.98
## 192 2015-02-19         1       0.12           48.10
## 193 2015-02-21         1       0.12           48.22
## 194 2015-02-22         1       0.12           48.34
## 195 2015-02-23         1       0.12           48.46
## 196 2015-02-24         1       0.12           48.58
## 197 2015-02-27         1       0.12           48.70
## 198 2015-03-01         1       0.12           48.82
## 199 2015-03-03         1       0.12           48.94
## 200 2015-03-06         1       0.12           49.06
## 201 2015-03-07         1       0.12           49.18
## 202 2015-03-08         1       0.12           49.30
## 203 2015-03-09         1       0.12           49.42
## 204 2015-03-10         1       0.12           49.54
## 205 2015-03-11         1       0.12           49.66
## 206 2015-03-13         1       0.12           49.78
## 207 2015-03-14         1       0.12           49.90
## 208 2015-03-15         1       0.12           50.02
## 209 2015-03-16         1       0.12           50.14
## 210 2015-03-19         1       0.12           50.26
## 211 2015-03-20         1       0.12           50.38
## 212 2015-03-22         1       0.12           50.50
## 213 2015-03-24         1       0.12           50.62
## 214 2015-03-26         1       0.12           50.74
## 215 2015-03-28         1       0.12           50.86
## 216 2015-04-02         1       0.12           50.98
## 217 2015-04-03         1       0.12           51.10
## 218 2015-04-07         1       0.12           51.22
## 219 2015-04-10         1       0.12           51.34
## 220 2015-04-11         1       0.12           51.46
## 221 2015-04-12         1       0.12           51.58
## 222 2015-04-13         1       0.12           51.70
## 223 2015-04-14         1       0.12           51.82
## 224 2015-04-15         1       0.12           51.94
## 225 2015-04-19         1       0.12           52.06
## 226 2015-04-20         1       0.12           52.18
## 227 2015-04-21         1       0.12           52.30
## 228 2015-04-22         1       0.12           52.42
## 229 2015-04-23         1       0.12           52.54
## 230 2015-04-26         1       0.12           52.66
## 231 2015-04-29         1       0.12           52.78
## 232 2015-04-30         1       0.12           52.90
## 233 2015-05-06         1       0.12           53.02
## 234 2015-05-08         1       0.12           53.14
## 235 2015-05-10         1       0.12           53.26
## 236 2015-05-11         1       0.12           53.38
## 237 2015-05-12         1       0.12           53.50
## 238 2015-05-13         1       0.12           53.62
## 239 2015-05-15         1       0.12           53.74
## 240 2015-05-21         1       0.12           53.86
## 241 2015-05-22         1       0.12           53.98
## 242 2015-05-23         1       0.12           54.10
## 243 2015-05-27         1       0.12           54.22
## 244 2015-05-28         1       0.12           54.34
## 245 2015-05-29         1       0.12           54.46
## 246 2015-06-01         1       0.12           54.58
## 247 2015-06-02         1       0.12           54.70
## 248 2015-06-04         1       0.12           54.82
## 249 2015-06-16         1       0.12           54.94
## 250 2015-06-20         1       0.12           55.06
## 251 2015-06-21         1       0.12           55.18
## 252 2015-06-22         1       0.12           55.30
## 253 2015-06-23         1       0.12           55.42
## 254 2015-06-28         1       0.12           55.54
## 255 2015-06-30         1       0.12           55.66
## 256 2015-07-03         1       0.12           55.78
## 257 2015-07-04         1       0.12           55.90
## 258 2015-07-08         1       0.12           56.02
## 259 2015-07-10         1       0.12           56.14
## 260 2015-07-12         1       0.12           56.26
## 261 2015-07-16         1       0.12           56.38
## 262 2015-07-17         1       0.12           56.50
## 263 2015-07-20         1       0.12           56.62
## 264 2015-07-21         1       0.12           56.74
## 265 2015-07-22         1       0.12           56.86
## 266 2015-07-24         1       0.12           56.98
## 267 2015-07-26         1       0.12           57.10
## 268 2015-07-28         1       0.12           57.22
## 269 2015-08-08         1       0.12           57.34
## 270 2015-08-10         1       0.12           57.46
## 271 2015-08-12         1       0.12           57.58
## 272 2015-08-18         1       0.12           57.70
## 273 2015-08-21         1       0.12           57.82
## 274 2015-08-24         1       0.12           57.94
## 275 2015-08-26         1       0.12           58.06
## 276 2015-08-27         1       0.12           58.18
## 277 2015-09-05         1       0.12           58.30
## 278 2015-09-12         1       0.12           58.42
## 279 2015-09-15         1       0.12           58.54
## 280 2015-09-16         1       0.12           58.66
## 281 2015-09-17         1       0.12           58.78
## 282 2015-09-18         1       0.12           58.90
## 283 2015-09-19         1       0.12           59.02
## 284 2015-09-22         1       0.12           59.14
## 285 2015-09-23         1       0.12           59.26
## 286 2015-09-25         1       0.12           59.38
## 287 2015-09-26         1       0.12           59.50
## 288 2015-09-27         1       0.12           59.62
## 289 2015-09-28         1       0.12           59.74
## 290 2015-09-30         1       0.12           59.86
## 291 2015-10-04         1       0.12           59.98
## 292 2015-10-05         1       0.12           60.10
## 293 2015-10-06         1       0.12           60.22
## 294 2015-10-13         1       0.12           60.34
## 295 2015-10-17         1       0.12           60.46
## 296 2015-10-24         1       0.12           60.58
## 297 2015-10-29         1       0.12           60.70
## 298 2015-10-31         1       0.12           60.82
## 299 2015-11-09         1       0.12           60.94
## 300 2015-11-15         1       0.12           61.06
## 301 2015-11-22         1       0.12           61.18
## 302 2015-11-26         1       0.12           61.30
## 303 2015-12-03         1       0.12           61.42
## 304 2015-12-06         1       0.12           61.54
## 305 2015-12-09         1       0.12           61.66
## 306 2015-12-10         1       0.12           61.78
## 307 2015-12-11         1       0.12           61.90
## 308 2015-12-12         1       0.12           62.02
## 309 2015-12-15         1       0.12           62.14
## 310 2015-12-21         1       0.12           62.26
## 311 2015-12-24         1       0.12           62.38
## 312 2015-12-26         1       0.12           62.50
## 313 2015-12-27         1       0.12           62.62
## 314 2015-12-29         1       0.12           62.74
## 315 2016-01-03         1       0.12           62.86
## 316 2016-01-09         1       0.12           62.98
## 317 2016-01-10         1       0.12           63.10
## 318 2016-01-13         1       0.12           63.22
## 319 2016-01-14         1       0.12           63.34
## 320 2016-01-15         1       0.12           63.46
## 321 2016-01-16         1       0.12           63.58
## 322 2016-01-18         1       0.12           63.70
## 323 2016-01-19         1       0.12           63.82
## 324 2016-01-21         1       0.12           63.94
## 325 2016-01-22         1       0.12           64.06
## 326 2016-01-25         1       0.12           64.18
## 327 2016-01-26         1       0.12           64.30
## 328 2016-01-28         1       0.12           64.42
## 329 2016-01-29         1       0.12           64.54
## 330 2016-01-30         1       0.12           64.66
## 331 2016-01-31         1       0.12           64.78
## 332 2016-02-01         1       0.12           64.90
## 333 2016-02-02         1       0.12           65.02
## 334 2016-02-04         1       0.12           65.14
## 335 2016-02-05         1       0.12           65.26
## 336 2016-02-06         1       0.12           65.38
## 337 2016-02-09         1       0.12           65.50
## 338 2016-02-12         1       0.12           65.62
## 339 2016-02-13         1       0.12           65.74
## 340 2016-02-14         1       0.12           65.86
## 341 2016-02-15         1       0.12           65.98
## 342 2016-02-17         1       0.12           66.10
## 343 2016-02-21         1       0.12           66.22
## 344 2016-02-22         1       0.12           66.34
## 345 2016-02-24         1       0.12           66.46
## 346 2016-02-25         1       0.12           66.58
## 347 2016-02-26         1       0.12           66.70
## 348 2016-02-28         1       0.12           66.82
## 349 2016-02-29         1       0.12           66.94
## 350 2016-03-02         1       0.12           67.06
## 351 2016-03-03         1       0.12           67.18
## 352 2016-03-04         1       0.12           67.30
## 353 2016-03-05         1       0.12           67.42
## 354 2016-03-07         1       0.12           67.54
## 355 2016-03-08         1       0.12           67.66
## 356 2016-05-02         1       0.12           67.78
## 357 2016-05-03         1       0.12           67.90
## 358 2016-05-04         1       0.12           68.02
## 359 2016-05-05         1       0.12           68.14
## 360 2016-05-06         1       0.12           68.26
## 361 2016-05-07         1       0.12           68.38
## 362 2016-05-08         1       0.12           68.50
## 363 2016-05-09         1       0.12           68.62
## 364 2016-05-10         1       0.12           68.74
## 365 2016-05-11         1       0.12           68.86
## 366 2016-05-13         1       0.12           68.98
## 367 2016-05-14         1       0.12           69.10
## 368 2016-05-15         1       0.12           69.22
## 369 2016-05-16         1       0.12           69.34
## 370 2016-05-31         1       0.12           69.46
## 371 2016-06-22         1       0.12           69.58
## 372 2016-06-25         1       0.12           69.70
## 373 2016-06-26         1       0.12           69.82
## 374 2016-06-28         1       0.12           69.94
## 375 2016-06-29         1       0.12           70.06
## 376 2016-06-30         1       0.12           70.18
## 377 2016-07-04         1       0.12           70.30
## 378 2016-07-05         1       0.12           70.42
## 379 2016-07-06         1       0.12           70.54
## 380 2016-07-11         1       0.12           70.66
## 381 2016-07-24         1       0.12           70.78
## 382 2016-07-27         1       0.12           70.90
## 383 2016-08-05         1       0.12           71.02
## 384 2016-08-15         1       0.12           71.14
## 385 2016-08-17         1       0.12           71.26
## 386 2016-08-18         1       0.12           71.38
## 387 2016-08-22         1       0.12           71.50
## 388 2016-08-25         1       0.12           71.62
## 389 2016-08-28         1       0.12           71.74
## 390 2016-09-06         1       0.12           71.86
## 391 2016-09-09         1       0.12           71.98
## 392 2016-09-16         1       0.12           72.10
## 393 2016-09-19         1       0.12           72.22
## 394 2016-09-20         1       0.12           72.34
## 395 2016-09-23         1       0.12           72.46
## 396 2016-10-01         1       0.12           72.58
## 397 2016-10-12         1       0.12           72.70
## 398 2016-10-21         1       0.12           72.82
## 399 2016-10-22         1       0.12           72.94
## 400 2016-11-03         1       0.12           73.06
## 401 2016-11-07         1       0.12           73.18
## 402 2016-11-15         1       0.12           73.30
## 403 2016-11-16         1       0.12           73.42
## 404 2016-11-17         1       0.12           73.54
## 405 2016-11-22         1       0.12           73.66
## 406 2016-11-28         1       0.12           73.78
## 407 2016-11-30         1       0.12           73.90
## 408 2016-12-15         1       0.12           74.02
## 409 2016-12-22         1       0.12           74.14
## 410 2016-12-23         1       0.12           74.26
## 411 2016-12-25         1       0.12           74.38
## 412 2017-01-16         1       0.12           74.50
## 413 2017-01-21         1       0.12           74.62
## 414 2017-01-30         1       0.12           74.74
## 415 2017-02-04         1       0.12           74.86
## 416 2017-03-04         1       0.12           74.98
## 417 2017-03-06         1       0.12           75.10
## 418 2017-03-10         1       0.12           75.22
## 419 2017-03-18         1       0.12           75.34
## 420 2017-03-21         1       0.12           75.46
## 421 2017-03-22         1       0.12           75.58
## 422 2017-03-23         1       0.12           75.70
## 423 2017-03-24         1       0.12           75.82
## 424 2017-03-25         1       0.12           75.94
## 425 2017-03-26         1       0.12           76.06
## 426 2017-03-28         1       0.12           76.18
## 427 2017-04-01         1       0.12           76.30
## 428 2017-04-04         1       0.12           76.42
## 429 2017-04-05         1       0.12           76.54
## 430 2017-04-11         1       0.12           76.66
## 431 2017-04-12         1       0.12           76.78
## 432 2017-04-13         1       0.12           76.90
## 433 2017-04-22         1       0.12           77.02
## 434 2017-04-25         1       0.12           77.14
## 435 2017-04-26         1       0.12           77.26
## 436 2017-04-30         1       0.12           77.38
## 437 2017-05-06         1       0.12           77.50
## 438 2017-07-14         1       0.12           77.62
## 439 2017-07-25         1       0.12           77.74
## 440 2017-07-28         1       0.12           77.86
## 441 2017-08-05         1       0.12           77.98
## 442 2017-08-06         1       0.12           78.10
## 443 2017-08-23         1       0.12           78.22
## 444 2017-08-25         1       0.12           78.34
## 445 2017-08-26         1       0.12           78.46
## 446 2017-09-04         1       0.12           78.58
## 447 2017-09-11         1       0.12           78.70
## 448 2017-09-20         1       0.12           78.82
## 449 2017-09-21         1       0.12           78.94
## 450 2017-09-26         1       0.12           79.06
## 451 2017-10-02         1       0.12           79.18
## 452 2017-10-15         1       0.12           79.30
## 453 2017-10-16         1       0.12           79.42
## 454 2017-10-21         1       0.12           79.54
## 455 2017-10-23         1       0.12           79.66
## 456 2017-10-29         1       0.12           79.78
## 457 2017-10-30         1       0.12           79.90
## 458 2017-11-06         1       0.12           80.02
## 459 2017-11-12         1       0.12           80.14
## 460 2017-11-20         1       0.12           80.26
## 461 2017-11-23         1       0.12           80.38
## 462 2017-11-26         1       0.12           80.50
## 463 2017-12-04         1       0.12           80.62
## 464 2017-12-07         1       0.12           80.74
## 465 2017-12-10         1       0.12           80.86
## 466 2017-12-12         1       0.12           80.98
## 467 2017-12-21         1       0.12           81.10
## 468 2017-12-22         1       0.12           81.22
## 469 2017-12-23         1       0.12           81.34
## 470 2017-12-24         1       0.12           81.46
## 471 2017-12-25         1       0.12           81.58
## 472 2017-12-26         1       0.12           81.70
## 473 2017-12-27         1       0.12           81.82
## 474 2018-01-05         1       0.12           81.94
## 475 2018-01-10         1       0.12           82.06
## 476 2018-01-18         1       0.12           82.18
## 477 2018-01-28         1       0.12           82.30
## 478 2018-02-01         1       0.12           82.42
## 479 2018-02-09         1       0.12           82.54
## 480 2018-02-10         1       0.12           82.66
## 481 2018-02-11         1       0.12           82.78
## 482 2018-02-18         1       0.12           82.90
## 483 2018-02-21         1       0.12           83.02
## 484 2018-02-24         1       0.12           83.14
## 485 2018-02-28         1       0.12           83.26
## 486 2018-03-05         1       0.12           83.38
## 487 2018-03-08         1       0.12           83.50
## 488 2018-03-09         1       0.12           83.62
## 489 2018-03-10         1       0.12           83.74
## 490 2018-03-11         1       0.12           83.86
## 491 2018-03-12         1       0.12           83.98
## 492 2018-03-22         1       0.12           84.10
## 493 2018-03-24         1       0.12           84.22
## 494 2018-03-28         1       0.12           84.34
## 495 2018-03-31         1       0.12           84.46
## 496 2018-04-08         1       0.12           84.58
## 497 2018-04-09         1       0.12           84.70
## 498 2018-04-10         1       0.12           84.82
## 499 2018-04-11         1       0.12           84.94
## 500 2018-04-16         1       0.12           85.06
## 501 2018-04-19         1       0.12           85.18
## 502 2018-04-30         1       0.12           85.30
## 503 2018-05-04         1       0.12           85.42
## 504 2018-05-05         1       0.12           85.54
## 505 2018-05-15         1       0.12           85.66
## 506 2018-05-16         1       0.12           85.78
## 507 2018-05-17         1       0.12           85.90
## 508 2018-05-18         1       0.12           86.02
## 509 2018-05-22         1       0.12           86.14
## 510 2018-05-27         1       0.12           86.26
## 511 2018-06-08         1       0.12           86.38
## 512 2018-06-19         1       0.12           86.50
## 513 2018-06-25         1       0.12           86.62
## 514 2018-06-26         1       0.12           86.74
## 515 2018-07-01         1       0.12           86.86
## 516 2018-07-02         1       0.12           86.98
## 517 2018-07-16         1       0.12           87.10
## 518 2018-07-24         1       0.12           87.22
## 519 2018-07-26         1       0.12           87.34
## 520 2018-07-28         1       0.12           87.46
## 521 2018-08-05         1       0.12           87.58
## 522 2018-08-10         1       0.12           87.70
## 523 2018-08-11         1       0.12           87.82
## 524 2018-08-14         1       0.12           87.94
## 525 2018-08-15         1       0.12           88.06
## 526 2018-08-18         1       0.12           88.18
## 527 2018-08-28         1       0.12           88.30
## 528 2018-08-29         1       0.12           88.42
## 529 2018-08-30         1       0.12           88.54
## 530 2018-08-31         1       0.12           88.66
## 531 2018-09-01         1       0.12           88.78
## 532 2018-09-13         1       0.12           88.90
## 533 2018-09-14         1       0.12           89.02
## 534 2018-09-16         1       0.12           89.14
## 535 2018-09-30         1       0.12           89.26
## 536 2018-10-01         1       0.12           89.38
## 537 2018-10-02         1       0.12           89.50
## 538 2018-10-03         1       0.12           89.62
## 539 2018-10-10         1       0.12           89.74
## 540 2018-10-18         1       0.12           89.86
## 541 2018-10-19         1       0.12           89.98
## 542 2018-10-29         1       0.12           90.10
## 543 2018-11-03         1       0.12           90.22
## 544 2018-11-04         1       0.12           90.34
## 545 2018-11-05         1       0.12           90.46
## 546 2018-11-06         1       0.12           90.58
## 547 2018-11-21         1       0.12           90.70
## 548 2018-11-24         1       0.12           90.82
## 549 2018-12-01         1       0.12           90.94
## 550 2018-12-05         1       0.12           91.06
## 551 2018-12-13         1       0.12           91.18
## 552 2018-12-19         1       0.12           91.30
## 553 2018-12-23         1       0.12           91.42
## 554 2019-01-02         1       0.12           91.54
## 555 2019-01-04         1       0.12           91.66
## 556 2019-01-05         1       0.12           91.78
## 557 2019-01-06         1       0.12           91.90
## 558 2019-01-07         1       0.12           92.02
## 559 2019-01-08         1       0.12           92.14
## 560 2019-01-19         1       0.12           92.26
## 561 2019-02-02         1       0.12           92.38
## 562 2019-02-03         1       0.12           92.50
## 563 2019-02-04         1       0.12           92.62
## 564 2019-02-05         1       0.12           92.74
## 565 2019-02-06         1       0.12           92.86
## 566 2019-02-07         1       0.12           92.98
## 567 2019-02-08         1       0.12           93.10
## 568 2019-02-11         1       0.12           93.22
## 569 2019-03-02         1       0.12           93.34
## 570 2019-03-08         1       0.12           93.46
## 571 2019-03-22         1       0.12           93.58
## 572 2019-04-07         1       0.12           93.70
## 573 2019-04-12         1       0.12           93.82
## 574 2019-04-13         1       0.12           93.94
## 575 2019-04-14         1       0.12           94.06
## 576 2019-04-15         1       0.12           94.18
## 577 2019-04-20         1       0.12           94.30
## 578 2019-04-25         1       0.12           94.42
## 579 2019-04-28         1       0.12           94.54
## 580 2019-05-11         1       0.12           94.66
## 581 2019-05-12         1       0.12           94.78
## 582 2019-05-19         1       0.12           94.90
## 583 2019-05-25         1       0.12           95.02
## 584 2019-06-09         1       0.12           95.14
## 585 2019-06-16         1       0.12           95.26
## 586 2019-06-17         1       0.12           95.38
## 587 2019-06-18         1       0.12           95.50
## 588 2019-06-19         1       0.12           95.62
## 589 2019-06-20         1       0.12           95.74
## 590 2019-06-29         1       0.12           95.86
## 591 2019-07-04         1       0.12           95.98
## 592 2019-07-17         1       0.12           96.10
## 593 2019-07-19         1       0.12           96.22
## 594 2019-07-20         1       0.12           96.34
## 595 2019-07-21         1       0.12           96.46
## 596 2019-07-22         1       0.12           96.58
## 597 2019-07-23         1       0.12           96.70
## 598 2019-07-24         1       0.12           96.82
## 599 2019-07-29         1       0.12           96.94
## 600 2019-08-20         1       0.12           97.06
## 601 2019-09-18         1       0.12           97.18
## 602 2019-09-20         1       0.12           97.30
## 603 2019-10-22         1       0.12           97.42
## 604 2019-11-18         1       0.12           97.54
## 605 2019-11-19         1       0.12           97.66
## 606 2019-11-20         1       0.12           97.78
## 607 2019-11-21         1       0.12           97.90
## 608 2019-11-22         1       0.12           98.02
## 609 2019-11-23         1       0.12           98.14
## 610 2019-11-27         1       0.12           98.26
## 611 2019-12-16         1       0.12           98.38
## 612 2019-12-19         1       0.12           98.50
## 613 2019-12-20         1       0.12           98.62
## 614 2020-01-10         1       0.12           98.74
## 615 2020-01-21         1       0.12           98.86
## 616 2020-01-26         1       0.12           98.98
## 617 2020-01-27         1       0.12           99.10
## 618 2020-01-28         1       0.12           99.22
## 619 2020-01-29         1       0.12           99.34
## 620 2020-02-10         1       0.12           99.46
## 621 2020-02-22         1       0.12           99.58
## 622 2020-02-26         1       0.12           99.70
## 623 2020-03-08         1       0.12           99.82
## 624 2020-03-17         1       0.12           99.94
## 625 2020-03-25         1       0.12          100.06
## 626 2020-04-09         1       0.12          100.18
## 627 2020-04-19         1       0.12          100.30
## 628 2020-04-24         1       0.12          100.42
## 629 2020-05-09         1       0.12          100.54
## 630 2020-05-12         1       0.12          100.66
## 631 2020-05-13         1       0.12          100.78
## 632 2020-05-14         1       0.12          100.90
## 633 2020-05-15         1       0.12          101.02
## 634 2020-05-26         1       0.12          101.14
## 635 2020-06-10         1       0.12          101.26
## 636 2020-06-11         1       0.12          100.00

##                              symptom_id frequency percentage cumulative_perc
## 1  0239f552-c6b3-42ff-8005-0d45ea1f8962       308      36.02           36.02
## 2  bdd8fb86-4cbf-4832-b975-742cd3109215       182      21.29           57.31
## 3  54bb1081-2244-41cf-baf7-47beb31ea4d2       100      11.70           69.01
## 4  86a80065-96fb-4069-ad49-2c100b866914        77       9.01           78.02
## 5  c8c60842-b805-41ba-b7b9-d772e39ff3b5        66       7.72           85.74
## 6  a2c90fad-596d-4cb9-a4c0-a840af41e574        41       4.80           90.54
## 7                                  <NA>        18       2.11           92.65
## 8  a2fcc57c-1f75-4411-877b-b82cf6d9ed0b        17       1.99           94.64
## 9  0fa4d6da-91de-4504-a578-4bcc75d525c8        14       1.64           96.28
## 10 fc56b772-6b14-45f3-aaec-76efe14f401d         7       0.82           97.10
## 11 2a50ec7a-7d5c-462a-8004-076e552e84ec         4       0.47           97.57
## 12 cc0cc290-cbb2-464f-8174-9a5bce0fe639         4       0.47           98.04
## 13                                    0         1       0.12           98.16
## 14 158f47bc-b2c5-463e-bffe-59db9423fe00         1       0.12           98.28
## 15 33255143-8303-4453-b22b-8acc17be5089         1       0.12           98.40
## 16 36e174ac-8a13-4ab0-9e96-6fbd6f890fa5         1       0.12           98.52
## 17 3f06bd87-7111-4b1e-b0e9-7affac3702c6         1       0.12           98.64
## 18 4c4f63de-cc59-4249-95ed-878129f2178e         1       0.12           98.76
## 19 56df8fa6-47e0-45f2-93d0-6ea612609007         1       0.12           98.88
## 20 67d1d557-6482-4465-a1cb-a5d9374ed188         1       0.12           99.00
## 21 6eef6051-d2b4-4812-af17-7e5f4d3193d7         1       0.12           99.12
## 22 77de7f81-105e-4ddd-9828-667741b07dab         1       0.12           99.24
## 23 8110c0d4-4cf9-44e1-b1e4-2945ed35a6d4         1       0.12           99.36
## 24 8a63e2b4-61d7-43af-904d-9eff6e93392a         1       0.12           99.48
## 25 9c86dea7-6a8e-401f-9692-90e6ee0d23d7         1       0.12           99.60
## 26 b5a9080d-e2dc-42bc-b85b-a9f9cd9d5a59         1       0.12           99.72
## 27 ea62cb53-18f0-4f27-a236-8bd695926a8b         1       0.12           99.84
## 28 f93bc06f-1489-410b-a02b-d0dd05d6fce5         1       0.12           99.96
## 29 fd03ae70-ad11-4b31-ada8-f33ada07f92f         1       0.12          100.00

##                        name.x frequency percentage cumulative_perc
## 1             Relación sexual       308      36.02           36.02
## 2                Menstruación       182      21.29           57.31
## 3                        Peso       100      11.70           69.01
## 4           Test de ovulación        77       9.01           78.02
## 5               Citas médicas        66       7.72           85.74
## 6                Medicamentos        41       4.80           90.54
## 7                        <NA>        19       2.22           92.76
## 8                 Temperatura        17       1.99           94.75
## 9         Prueba del embarazo        14       1.64           96.39
## 10          Dolores de cabeza         7       0.82           97.21
## 11          Náuseas / vomitos         4       0.47           97.68
## 12           Pechos sensibles         4       0.47           98.15
## 13               Acné cíclico         1       0.12           98.27
## 14      Calambres abdominales         1       0.12           98.39
## 15          Cervical apertura         1       0.12           98.51
## 16              Día del ciclo         1       0.12           98.63
## 17                Día del mes         1       0.12           98.75
## 18 Dolor muscular / articular         1       0.12           98.87
## 19            Estado de ánimo         1       0.12           98.99
## 20           Firmeza cervical         1       0.12           99.11
## 21                  Hinchazón         1       0.12           99.23
## 22                   Insomnio         1       0.12           99.35
## 23        Manchado / Sangrado         1       0.12           99.47
## 24      Menstruación prevista         1       0.12           99.59
## 25              Moco cervical         1       0.12           99.71
## 26                      Notas         1       0.12           99.83
## 27         Ovulación prevista         1       0.12           99.95
## 28          Posición cervical         1       0.12          100.00

##    num.x frequency percentage cumulative_perc
## 1      0       308      36.02           36.02
## 2  -9999       182      21.29           57.31
## 3  -9986       100      11.70           69.01
## 4     12        77       9.01           78.02
## 5     14        66       7.72           85.74
## 6     13        41       4.80           90.54
## 7   <NA>        19       2.22           92.76
## 8  -9987        17       1.99           94.75
## 9     11        14       1.64           96.39
## 10     2         7       0.82           97.21
## 11     3         4       0.47           97.68
## 12     7         4       0.47           98.15
## 13 -8998         1       0.12           98.27
## 14 -8999         1       0.12           98.39
## 15 -9994         1       0.12           98.51
## 16 -9995         1       0.12           98.63
## 17 -9998         1       0.12           98.75
## 18     1         1       0.12           98.87
## 19    10         1       0.12           98.99
## 20    15         1       0.12           99.11
## 21    16         1       0.12           99.23
## 22    17         1       0.12           99.35
## 23    18         1       0.12           99.47
## 24     4         1       0.12           99.59
## 25     5         1       0.12           99.71
## 26     6         1       0.12           99.83
## 27     8         1       0.12           99.95
## 28     9         1       0.12          100.00

##   mode frequency percentage cumulative_perc
## 1    0       719      84.09           84.09
## 2    1       117      13.68           97.77
## 3 <NA>        19       2.22          100.00

##    type frequency percentage cumulative_perc
## 1     1       408      47.72           47.72
## 2     4       308      36.02           83.74
## 3     2        78       9.12           92.86
## 4  <NA>        19       2.22           95.08
## 5     °        17       1.99           97.07
## 6     9        14       1.64           98.71
## 7     6         8       0.94           99.65
## 8     5         1       0.12           99.77
## 9     7         1       0.12           99.89
## 10    8         1       0.12          100.00

##                                  layout frequency percentage cumulative_perc
## 1                                     2       308      36.02           36.02
## 2                                     0       191      22.34           58.36
## 3                                     3       183      21.40           79.76
## 4                                     7        66       7.72           87.48
## 5                                     5        41       4.80           92.28
## 6                                     1        26       3.04           95.32
## 7                                  <NA>        19       2.22           97.54
## 8  2a50ec7a-7d5c-462a-8004-076e552e84ec         4       0.47           98.01
## 9  cc0cc290-cbb2-464f-8174-9a5bce0fe639         4       0.47           98.48
## 10                                   -1         3       0.35           98.83
## 11 33255143-8303-4453-b22b-8acc17be5089         1       0.12           98.95
## 12 36e174ac-8a13-4ab0-9e96-6fbd6f890fa5         1       0.12           99.07
## 13 4c4f63de-cc59-4249-95ed-878129f2178e         1       0.12           99.19
## 14 56df8fa6-47e0-45f2-93d0-6ea612609007         1       0.12           99.31
## 15 67d1d557-6482-4465-a1cb-a5d9374ed188         1       0.12           99.43
## 16                                    8         1       0.12           99.55
## 17 8a63e2b4-61d7-43af-904d-9eff6e93392a         1       0.12           99.67
## 18 9c86dea7-6a8e-401f-9692-90e6ee0d23d7         1       0.12           99.79
## 19 ea62cb53-18f0-4f27-a236-8bd695926a8b         1       0.12           99.91
## 20 fd03ae70-ad11-4b31-ada8-f33ada07f92f         1       0.12          100.00

##                                   chart frequency percentage cumulative_perc
## 1                                     0       432      50.53           50.53
## 2                                     1       183      21.40           71.93
## 3  54bb1081-2244-41cf-baf7-47beb31ea4d2       100      11.70           83.63
## 4  86a80065-96fb-4069-ad49-2c100b866914        77       9.01           92.64
## 5                                  <NA>        19       2.22           94.86
## 6  0fa4d6da-91de-4504-a578-4bcc75d525c8        14       1.64           96.50
## 7  fc56b772-6b14-45f3-aaec-76efe14f401d         7       0.82           97.32
## 8                     Náuseas / vomitos         4       0.47           97.79
## 9                      Pechos sensibles         4       0.47           98.26
## 10                                   -1         2       0.23           98.49
## 11 158f47bc-b2c5-463e-bffe-59db9423fe00         1       0.12           98.61
## 12 6eef6051-d2b4-4812-af17-7e5f4d3193d7         1       0.12           98.73
## 13 77de7f81-105e-4ddd-9828-667741b07dab         1       0.12           98.85
## 14                         Acné cíclico         1       0.12           98.97
## 15                Calambres abdominales         1       0.12           99.09
## 16                    Cervical apertura         1       0.12           99.21
## 17           Dolor muscular / articular         1       0.12           99.33
## 18 f93bc06f-1489-410b-a02b-d0dd05d6fce5         1       0.12           99.45
## 19                     Firmeza cervical         1       0.12           99.57
## 20                            Hinchazón         1       0.12           99.69
## 21                             Insomnio         1       0.12           99.81
## 22                  Manchado / Sangrado         1       0.12           99.93
## 23                    Posición cervical         1       0.12          100.00

##                                category frequency percentage cumulative_perc
## 1  0239f552-c6b3-42ff-8005-0d45ea1f8962       308      36.02           36.02
## 2                                     0       182      21.29           57.31
## 3                                  Peso       100      11.70           69.01
## 4                     Test de ovulación        77       9.01           78.02
## 5  c8c60842-b805-41ba-b7b9-d772e39ff3b5        66       7.72           85.74
## 6  a2c90fad-596d-4cb9-a4c0-a840af41e574        41       4.80           90.54
## 7                                  <NA>        19       2.22           92.76
## 8  a2fcc57c-1f75-4411-877b-b82cf6d9ed0b        17       1.99           94.75
## 9                   Prueba del embarazo        14       1.64           96.39
## 10                    Dolores de cabeza         7       0.82           97.21
## 11                                    3         4       0.47           97.68
## 12                                    7         4       0.47           98.15
## 13                                   10         1       0.12           98.27
## 14                                   16         1       0.12           98.39
## 15                                   17         1       0.12           98.51
## 16                                   18         1       0.12           98.63
## 17 3f06bd87-7111-4b1e-b0e9-7affac3702c6         1       0.12           98.75
## 18                                    4         1       0.12           98.87
## 19                                    5         1       0.12           98.99
## 20                                    6         1       0.12           99.11
## 21                                    8         1       0.12           99.23
## 22 8110c0d4-4cf9-44e1-b1e4-2945ed35a6d4         1       0.12           99.35
## 23                                    9         1       0.12           99.47
## 24 b5a9080d-e2dc-42bc-b85b-a9f9cd9d5a59         1       0.12           99.59
## 25                        Día del ciclo         1       0.12           99.71
## 26                Menstruación prevista         1       0.12           99.83
## 27                        Moco cervical         1       0.12           99.95
## 28                   Ovulación prevista         1       0.12          100.00
## 
##                                     id.x frequency percentage cumulative_perc
## 1                                   <NA>       738      86.32           86.32
## 2   009f6884-11f7-4d4e-8b1b-05c809f9be12         1       0.12           86.44
## 3   0141878b-80d4-44dc-8964-46bd870e39db         1       0.12           86.56
## 4   0292b053-4f55-4f77-97dc-91f7a6dc2341         1       0.12           86.68
## 5   03fbc39f-b17f-41cd-8d09-c1fb7e0f5951         1       0.12           86.80
## 6   0b992fff-4835-41a7-8a20-0813ea811087         1       0.12           86.92
## 7   0f1cf32d-49a6-44ab-99a1-9919dc0816aa         1       0.12           87.04
## 8   0f5b7e94-696e-42d8-9008-9d6718bada3d         1       0.12           87.16
## 9   114cd32d-dc78-4c46-9e84-7a931204def5         1       0.12           87.28
## 10  1286a1a9-7cb3-44eb-a863-11084c689914         1       0.12           87.40
## 11  175d95b1-33ee-47ec-a825-e1c40724c490         1       0.12           87.52
## 12  1aa242f5-feeb-416f-b509-9b7c4caf04c0         1       0.12           87.64
## 13  1c87bfc6-d5e2-42dd-ac64-1de87962f370         1       0.12           87.76
## 14  1fa638c7-d392-40a0-9944-8d13117147e1         1       0.12           87.88
## 15  2019a077-50af-4fe9-ab4e-01a207885f9e         1       0.12           88.00
## 16  24f9d316-2eec-4d01-bab3-131cb6d148f6         1       0.12           88.12
## 17  252ca8f2-b032-4e5f-908c-858e47a827fb         1       0.12           88.24
## 18  2975d8a0-32b7-4546-8adb-a6553098fa46         1       0.12           88.36
## 19  2ace358a-f14d-4fe9-9344-c3b437ad5b73         1       0.12           88.48
## 20  2c47e46d-1d11-4c62-b09e-de8a095a9933         1       0.12           88.60
## 21  2c5bcc0b-7c15-488e-a6ae-3a8fe615ff1c         1       0.12           88.72
## 22  2d7af972-bd43-4d00-b4cc-690477165908         1       0.12           88.84
## 23  31baec56-f915-4dee-8c99-b9ca03b20c45         1       0.12           88.96
## 24  32780a6d-e81c-443f-8ce2-290f25685538         1       0.12           89.08
## 25  38f7e1c6-e140-44d0-af64-b6ea0989657a         1       0.12           89.20
## 26  479fba03-0018-4cac-98c0-3aaf49a55bb9         1       0.12           89.32
## 27  49a10b71-196d-4602-af71-f8a8694e61d7         1       0.12           89.44
## 28  49c4de80-a5c4-4eac-af9a-b52c28970ec7         1       0.12           89.56
## 29  4bee07bc-4f57-41f5-9025-4ccd05ee0b8a         1       0.12           89.68
## 30  4e5a9eba-4f7d-4999-839a-ba09225109ff         1       0.12           89.80
## 31  4ef87e7e-b2bb-48c9-ba81-a978d2db77f2         1       0.12           89.92
## 32  505852e5-b705-42b7-a1cf-e77bf2674a89         1       0.12           90.04
## 33  52a7a27b-a913-4e21-9fe4-e252db7641ca         1       0.12           90.16
## 34  5ccc87ec-a3f7-45ff-ae95-b50bc1d708cf         1       0.12           90.28
## 35  5dea783d-7dcf-4cc8-afdc-63b0e9976f0a         1       0.12           90.40
## 36  5fd8bb7c-6243-4e67-937a-47adf713ca01         1       0.12           90.52
## 37  61619736-8fa8-4590-a6a6-ccecb5ec7f5c         1       0.12           90.64
## 38  616f76c7-1cdb-47f5-adfb-cddd11c54225         1       0.12           90.76
## 39  61d44209-e968-4af3-b9a6-0b24e4d2825c         1       0.12           90.88
## 40  61ea8af3-df8b-490d-a740-54d0c24a2fd3         1       0.12           91.00
## 41  64ccd022-4d41-4025-99d1-00d096a32b51         1       0.12           91.12
## 42  67c7b2dd-2a65-4a2d-8bd3-94cf561a1dde         1       0.12           91.24
## 43  695bdb63-7c1d-472f-b6d9-0c6b075b088a         1       0.12           91.36
## 44  6a538482-2223-40de-87fa-f711e52bd7fb         1       0.12           91.48
## 45  6fb6bb3f-5648-461b-bba8-f36800f9593b         1       0.12           91.60
## 46  6fbaf868-1e2a-49c0-8f39-96122403fb45         1       0.12           91.72
## 47  707fe1df-40c3-4703-a3fa-55d715b2655f         1       0.12           91.84
## 48  71adbecb-14d0-4135-b147-ee2fbbbbe54f         1       0.12           91.96
## 49  731c1a84-29a2-4c18-9006-90347d26a16a         1       0.12           92.08
## 50  76bbf481-beb8-42f1-84a3-12b399e310fc         1       0.12           92.20
## 51  79179bfb-c97d-41da-8942-1d2f9e296428         1       0.12           92.32
## 52  7d4e8ef7-6673-4729-9452-3ef604cac137         1       0.12           92.44
## 53  7d732639-d8a8-403b-b54f-de901c5e2333         1       0.12           92.56
## 54  7e6424bf-fccc-4cd7-98a7-65e274cd8dda         1       0.12           92.68
## 55  8018007d-733a-4f49-acb8-57ebe5567583         1       0.12           92.80
## 56  82477496-5650-4710-88ce-34cf7d98c866         1       0.12           92.92
## 57  867d49c8-4938-45f7-827d-066ff47381f4         1       0.12           93.04
## 58  86e58d8a-ec12-44bd-907e-b654271d243e         1       0.12           93.16
## 59  886f66d0-ac4e-464c-a986-53640cb4f617         1       0.12           93.28
## 60  8985d537-49a1-4b1d-99b0-310aeeef22f5         1       0.12           93.40
## 61  89c72186-96a0-4f24-bfc9-30a5a1791aaf         1       0.12           93.52
## 62  8b66908e-c63e-4c49-be51-06309b6b839e         1       0.12           93.64
## 63  8c8f6538-059e-4663-af2c-c3580d4f453e         1       0.12           93.76
## 64  8c9bf8e1-d8df-46c8-a08a-0ecc7fd82a1e         1       0.12           93.88
## 65  8c9f069d-d6a3-4d2f-b489-bb029e42a5a4         1       0.12           94.00
## 66  90acdbe6-9468-4dc7-ad91-ce03d217bdf7         1       0.12           94.12
## 67  92f68a3e-1b0c-4b53-9e1e-2a625218e741         1       0.12           94.24
## 68  93de1a0d-d4f2-4aa6-8b99-e34ce48e789a         1       0.12           94.36
## 69  93e8189f-8c3f-4c21-a969-83b931227d67         1       0.12           94.48
## 70  95bd3708-ef95-42f3-94dc-c1921e9f8fcf         1       0.12           94.60
## 71  95de4f80-70c2-4a31-84b3-c5beb5a0207a         1       0.12           94.72
## 72  9c351a15-006b-400f-a847-fbe54fd4d7d1         1       0.12           94.84
## 73  9cd967b8-5da6-413a-94c2-e02b7195d8a8         1       0.12           94.96
## 74  a238bb9e-b510-44a0-a435-3417831c00d4         1       0.12           95.08
## 75  a290cb92-dd32-459f-a6c0-8e36d658abfe         1       0.12           95.20
## 76  a5923237-e41c-4a5f-ab8a-91b105433a4e         1       0.12           95.32
## 77  a676ae84-3764-49af-88b4-7994c75d7772         1       0.12           95.44
## 78  a9327ee7-d08e-405a-bc60-6100d983695d         1       0.12           95.56
## 79  ac3ff79d-eb22-4552-83fd-f9a9d211ec8f         1       0.12           95.68
## 80  acca2320-2caf-4473-9817-e98f85acafea         1       0.12           95.80
## 81  afaff20d-dacd-4b0e-a1f1-f8d81e6ab9d3         1       0.12           95.92
## 82  b30e211d-f831-45bb-a0b5-0d1c4c2b64c2         1       0.12           96.04
## 83  b6616594-7898-4edb-9e11-5383e02d2bbe         1       0.12           96.16
## 84  b6636aec-d8fa-4c33-89ed-f50ee017ec67         1       0.12           96.28
## 85  b9580051-c662-4584-a8c5-bfd3b9ec3c94         1       0.12           96.40
## 86  b9992780-24d9-4198-93b1-5dd615ec0b6e         1       0.12           96.52
## 87  b9f07c5c-56e5-41d6-af04-ff8523c03358         1       0.12           96.64
## 88  bc2854a7-1d88-4bdc-9394-f4e7bd225696         1       0.12           96.76
## 89  bd8c4384-8713-4633-bcfa-7407ea688c46         1       0.12           96.88
## 90  bfbc2f59-1896-4f13-aa11-6c3c5a4e11d2         1       0.12           97.00
## 91  c068442e-a212-40c3-b027-6005774be399         1       0.12           97.12
## 92  c1136d00-97c6-4853-805a-9108d2967a04         1       0.12           97.24
## 93  c2ce232b-e6a7-4d2c-b865-b0f3c3dd0d6f         1       0.12           97.36
## 94  c92d7121-58bb-4471-92df-bdfa7a51ddd5         1       0.12           97.48
## 95  cd70e49b-a972-48d5-9cb7-b6265e812d53         1       0.12           97.60
## 96  cd7a8308-fc9f-489a-bf7f-2bd310962b10         1       0.12           97.72
## 97  d01a4b09-5f80-4ac7-9442-3c85844bb0f3         1       0.12           97.84
## 98  d41eae90-6db9-47f4-9043-f5fa9cc864cd         1       0.12           97.96
## 99  d6a225a2-83ed-447b-82d5-99dfa63591cd         1       0.12           98.08
## 100 d7c08024-5218-4d32-ba67-16e7a1ce2114         1       0.12           98.20
## 101 d9b7a748-719f-4dcc-9062-03f5f09384b7         1       0.12           98.32
## 102 dde3c5cf-ce90-4e8e-af2a-fb6fe0a7b755         1       0.12           98.44
## 103 df080b87-0ddd-404a-ae22-a237fcac008e         1       0.12           98.56
## 104 df5cd6fc-b2e7-4d23-b75d-5c000abcd1af         1       0.12           98.68
## 105 e00e03b3-9708-475c-9cd6-52cefd78a32d         1       0.12           98.80
## 106 e05f5fce-d669-49c1-8d87-1d9d08331d92         1       0.12           98.92
## 107 e1458981-6963-4d33-8972-4cb1fcededc5         1       0.12           99.04
## 108 e3e86bc0-ab8e-4be5-81c1-c90a0b3d0798         1       0.12           99.16
## 109 e4931a3a-fbc9-4ce9-928c-31c987026495         1       0.12           99.28
## 110 e4aea38a-d5af-4f9b-b09b-707d0da39e05         1       0.12           99.40
## 111 e99b0d6e-6925-4744-8c55-8ff4c31b48c2         1       0.12           99.52
## 112 ec3f4bce-65b0-4787-8901-d733baf1f8d6         1       0.12           99.64
## 113 ee17a51b-3549-442b-8729-6c48316262ee         1       0.12           99.76
## 114 f15a167e-5390-403f-a5c2-adb996ddda16         1       0.12           99.88
## 115 f573ddc8-7ca7-41ab-989b-508b2c77e5da         1       0.12          100.00
## 116 f5b93dce-1016-4acf-bd0b-c602f9cc54d1         1       0.12          100.12
## 117 f775a24e-e538-4808-b96e-29960b8cc32a         1       0.12          100.24
## 118 fd2ed856-ce1a-48ef-b2aa-8f117fbe4f5a         1       0.12          100.00
## 
##                datetime frequency percentage cumulative_perc
## 1                  <NA>       738      86.32           86.32
## 2   2013-06-04T09:50:00         1       0.12           86.44
## 3   2013-06-09T10:02:00         1       0.12           86.56
## 4   2013-06-10T06:50:00         1       0.12           86.68
## 5   2013-06-14T09:15:00         1       0.12           86.80
## 6   2013-06-27T09:07:00         1       0.12           86.92
## 7   2013-07-24T09:51:00         1       0.12           87.04
## 8   2013-07-31T10:32:00         1       0.12           87.16
## 9   2013-08-02T14:30:00         1       0.12           87.28
## 10  2013-08-19T09:06:00         1       0.12           87.40
## 11  2013-08-23T10:42:00         1       0.12           87.52
## 12  2013-08-24T08:23:00         1       0.12           87.64
## 13  2013-09-05T07:19:00         1       0.12           87.76
## 14  2013-09-09T08:40:00         1       0.12           87.88
## 15  2013-09-10T08:27:00         1       0.12           88.00
## 16  2013-09-15T10:30:00         1       0.12           88.12
## 17  2014-09-30T07:10:00         1       0.12           88.24
## 18  2014-10-01T06:02:00         1       0.12           88.36
## 19  2014-10-02T04:56:00         1       0.12           88.48
## 20  2014-10-03T06:23:00         1       0.12           88.60
## 21  2014-10-10T07:07:00         1       0.12           88.72
## 22  2014-10-13T06:11:00         1       0.12           88.84
## 23  2014-10-20T06:02:00         1       0.12           88.96
## 24  2014-10-22T06:57:00         1       0.12           89.08
## 25  2014-10-23T05:30:00         1       0.12           89.20
## 26  2014-10-24T06:10:00         1       0.12           89.32
## 27  2014-10-25T09:18:00         1       0.12           89.44
## 28  2014-10-27T06:36:00         1       0.12           89.56
## 29  2014-10-28T06:17:00         1       0.12           89.68
## 30  2014-10-29T05:42:00         1       0.12           89.80
## 31  2014-10-30T06:27:00         1       0.12           89.92
## 32  2014-10-31T06:03:00         1       0.12           90.04
## 33  2014-11-01T07:48:00         1       0.12           90.16
## 34  2014-11-26T06:18:00         1       0.12           90.28
## 35  2015-01-15T06:09:00         1       0.12           90.40
## 36  2015-02-03T06:03:00         1       0.12           90.52
## 37  2015-03-10T07:11:00         1       0.12           90.64
## 38  2015-03-30T20:44:00         1       0.12           90.76
## 39  2015-09-30T06:14:00         1       0.12           90.88
## 40  2015-10-14T06:12:00         1       0.12           91.00
## 41  2015-11-02T06:08:00         1       0.12           91.12
## 42  2015-11-03T06:09:00         1       0.12           91.24
## 43  2015-11-10T06:09:00         1       0.12           91.36
## 44  2015-11-11T06:09:00         1       0.12           91.48
## 45  2015-11-12T06:15:00         1       0.12           91.60
## 46  2015-11-16T06:01:00         1       0.12           91.72
## 47  2015-11-17T06:50:00         1       0.12           91.84
## 48  2015-11-26T06:14:00         1       0.12           91.96
## 49  2015-12-06T08:23:00         1       0.12           92.08
## 50  2015-12-07T06:17:00         1       0.12           92.20
## 51  2015-12-08T11:03:00         1       0.12           92.32
## 52  2015-12-20T10:45:00         1       0.12           92.44
## 53  2016-01-11T06:14:00         1       0.12           92.56
## 54  2016-01-12T06:12:00         1       0.12           92.68
## 55  2016-01-14T06:26:00         1       0.12           92.80
## 56  2016-01-15T06:47:00         1       0.12           92.92
## 57  2016-01-19T06:19:00         1       0.12           93.04
## 58  2016-01-21T06:10:00         1       0.12           93.16
## 59  2016-01-26T07:09:00         1       0.12           93.28
## 60  2016-01-28T06:18:00         1       0.12           93.40
## 61  2016-02-17T06:11:00         1       0.12           93.52
## 62  2016-03-01T06:12:00         1       0.12           93.64
## 63  2016-03-04T06:17:00         1       0.12           93.76
## 64  2016-03-07T06:11:00         1       0.12           93.88
## 65  2016-03-09T06:18:00         1       0.12           94.00
## 66  2016-06-20T07:17:00         1       0.12           94.12
## 67  2016-06-21T06:29:00         1       0.12           94.24
## 68  2016-06-30T10:09:00         1       0.12           94.36
## 69  2016-07-01T10:42:00         1       0.12           94.48
## 70  2016-07-05T07:18:00         1       0.12           94.60
## 71  2016-07-07T08:09:00         1       0.12           94.72
## 72  2016-07-15T08:44:00         1       0.12           94.84
## 73  2016-07-21T06:14:00         1       0.12           94.96
## 74  2016-07-26T07:11:00         1       0.12           95.08
## 75  2016-08-05T07:12:00         1       0.12           95.20
## 76  2016-08-09T07:14:00         1       0.12           95.32
## 77  2016-08-15T08:48:00         1       0.12           95.44
## 78  2016-08-30T08:57:00         1       0.12           95.56
## 79  2016-09-12T06:26:00         1       0.12           95.68
## 80  2016-09-13T06:35:00         1       0.12           95.80
## 81  2016-09-16T06:11:00         1       0.12           95.92
## 82  2016-09-29T06:20:00         1       0.12           96.04
## 83  2016-09-30T06:17:00         1       0.12           96.16
## 84  2016-10-04T06:10:00         1       0.12           96.28
## 85  2016-10-14T07:14:00         1       0.12           96.40
## 86  2016-10-19T06:20:00         1       0.12           96.52
## 87  2016-10-21T06:57:00         1       0.12           96.64
## 88  2016-11-03T07:14:00         1       0.12           96.76
## 89  2016-11-14T07:14:00         1       0.12           96.88
## 90  2017-04-12T10:00:00         1       0.12           97.00
## 91  2017-07-19T07:25:00         1       0.12           97.12
## 92  2017-07-20T08:01:00         1       0.12           97.24
## 93  2017-07-21T12:35:00         1       0.12           97.36
## 94  2017-07-22T12:35:00         1       0.12           97.48
## 95  2017-07-25T09:59:00         1       0.12           97.60
## 96  2017-07-27T07:38:00         1       0.12           97.72
## 97  2017-08-14T16:05:00         1       0.12           97.84
## 98  2017-08-21T08:19:00         1       0.12           97.96
## 99  2017-08-24T10:32:00         1       0.12           98.08
## 100 2017-08-25T09:33:00         1       0.12           98.20
## 101 2017-09-10T08:14:00         1       0.12           98.32
## 102 2017-09-11T07:45:00         1       0.12           98.44
## 103 2017-09-19T11:57:00         1       0.12           98.56
## 104 2017-09-21T07:19:00         1       0.12           98.68
## 105 2017-09-26T08:15:00         1       0.12           98.80
## 106 2017-10-02T07:17:00         1       0.12           98.92
## 107 2017-10-16T08:20:00         1       0.12           99.04
## 108 2017-10-29T09:09:00         1       0.12           99.16
## 109 2017-11-23T08:50:00         1       0.12           99.28
## 110 2017-11-28T21:15:00         1       0.12           99.40
## 111 2017-12-07T08:53:00         1       0.12           99.52
## 112 2017-12-11T07:19:00         1       0.12           99.64
## 113 2017-12-19T09:59:00         1       0.12           99.76
## 114 2018-01-05T07:35:00         1       0.12           99.88
## 115 2018-07-04T11:50:00         1       0.12          100.00
## 116 2018-08-08T07:18:00         1       0.12          100.12
## 117 2018-11-24T09:43:00         1       0.12          100.24
## 118 2019-01-05T09:47:00         1       0.12          100.00

##    value frequency percentage cumulative_perc
## 1   <NA>       738      86.32           86.32
## 2  70000         7       0.82           87.14
## 3  36700         5       0.58           87.72
## 4  36800         5       0.58           88.30
## 5  68700         5       0.58           88.88
## 6  70100         5       0.58           89.46
## 7  69500         4       0.47           89.93
## 8  69900         4       0.47           90.40
## 9  36600         3       0.35           90.75
## 10 68800         3       0.35           91.10
## 11 69200         3       0.35           91.45
## 12 70700         3       0.35           91.80
## 13 71100         3       0.35           92.15
## 14 73000         3       0.35           92.50
## 15 66400         2       0.23           92.73
## 16 66700         2       0.23           92.96
## 17 66800         2       0.23           93.19
## 18 66900         2       0.23           93.42
## 19 67700         2       0.23           93.65
## 20 68200         2       0.23           93.88
## 21 68900         2       0.23           94.11
## 22 69400         2       0.23           94.34
## 23 69700         2       0.23           94.57
## 24 70400         2       0.23           94.80
## 25 70600         2       0.23           95.03
## 26 70900         2       0.23           95.26
## 27 71200         2       0.23           95.49
## 28 73300         2       0.23           95.72
## 29 79900         2       0.23           95.95
## 30 36900         1       0.12           96.07
## 31 37000         1       0.12           96.19
## 32 37100         1       0.12           96.31
## 33 37300         1       0.12           96.43
## 34 66600         1       0.12           96.55
## 35 67000         1       0.12           96.67
## 36 67200         1       0.12           96.79
## 37 68000         1       0.12           96.91
## 38 68100         1       0.12           97.03
## 39 68300         1       0.12           97.15
## 40 68500         1       0.12           97.27
## 41 69000         1       0.12           97.39
## 42 69100         1       0.12           97.51
## 43 69300         1       0.12           97.63
## 44 69800         1       0.12           97.75
## 45 70200         1       0.12           97.87
## 46 70300         1       0.12           97.99
## 47 70500         1       0.12           98.11
## 48 71400         1       0.12           98.23
## 49 71700         1       0.12           98.35
## 50 72100         1       0.12           98.47
## 51 72400         1       0.12           98.59
## 52 72500         1       0.12           98.71
## 53 72900         1       0.12           98.83
## 54 73600         1       0.12           98.95
## 55 74100         1       0.12           99.07
## 56 75200         1       0.12           99.19
## 57 75300         1       0.12           99.31
## 58 76500         1       0.12           99.43
## 59 77600         1       0.12           99.55
## 60 78200         1       0.12           99.67
## 61 78300         1       0.12           99.79
## 62 78500         1       0.12           99.91
## 63 79000         1       0.12          100.00

##                                value_id frequency percentage cumulative_perc
## 1  b3128bcd-b057-4de1-b776-147dc6edb677       275      32.16           32.16
## 2                                  <NA>       150      17.54           49.70
## 3  44d8b929-c043-4e39-baf4-63dd5d04fe38        85       9.94           59.64
## 4  7442f43e-9551-4a4c-b2d5-ab73d180504a        74       8.65           68.29
## 5  23d86cea-d536-4343-ab59-a1bb86aec86e        68       7.95           76.24
## 6  cc56c587-77d5-489e-a650-f7814c6f30b0        47       5.50           81.74
## 7  a496d25e-8926-49ff-b1ab-6b944270a78a        33       3.86           85.60
## 8  2644c28d-dd59-4e26-b2be-58fc32e1e2f9        29       3.39           88.99
## 9  be8dc4f2-ebe8-4703-a0c1-f15a2eac4564        20       2.34           91.33
## 10 27223b7a-9667-4d59-b840-cd4e910541fd        10       1.17           92.50
## 11 7d32990a-6f26-4f12-87b5-98c68c2a5d23        10       1.17           93.67
## 12 a664523a-e041-47de-ab13-432b9c13c2a4        10       1.17           94.84
## 13 26b80cf4-a9f2-463f-8fd8-9930a99aaa04         8       0.94           95.78
## 14 ddc86eb2-9841-4d12-96ba-640b8888ce45         8       0.94           96.72
## 15 36c7ce93-71d9-4572-8842-f1859398d514         6       0.70           97.42
## 16 35b4bd7a-4b3b-4501-88a4-7cbe24349468         4       0.47           97.89
## 17 1be07fc1-2b81-43ea-8aa7-a540251286f7         3       0.35           98.24
## 18 3c1be397-349d-4788-b74e-bbdf0ba61e77         3       0.35           98.59
## 19 596edc61-94f5-4b57-86f9-27ed155f8a5f         3       0.35           98.94
## 20 62da543e-759e-4c1d-a8bc-c5ef80db18ca         3       0.35           99.29
## 21 71c53ed5-aa03-4b96-a511-3883c58942bd         1       0.12           99.41
## 22 900d961b-d818-4006-8073-1bc4e767e5b6         1       0.12           99.53
## 23 9bf1fc30-88df-4ad1-896b-ed5fa13d6d92         1       0.12           99.65
## 24 a3663320-c229-4efc-b972-ec20ccc7b93c         1       0.12           99.77
## 25 c0e12f9a-ee6f-426a-be24-392a641f43cc         1       0.12           99.89
## 26 f170f52d-0251-42f9-a0c4-b93d037823ab         1       0.12          100.00

##                       name.y frequency percentage cumulative_perc
## 1             Sin protección       275      32.16           32.16
## 2                       <NA>       150      17.54           49.70
## 3                     Ligera        85       9.94           59.64
## 4                   Negativo        82       9.59           69.23
## 5                   Moderada        68       7.95           77.18
## 6  Obstetricia y Ginecología        47       5.50           82.68
## 7                 Protegidas        33       3.86           86.54
## 8                    Intensa        29       3.39           89.93
## 9       Citrato de clomifeno        20       2.34           92.27
## 10                     Medio        11       1.29           93.56
## 11                       hCG        10       1.17           94.73
## 12               Laboratorio        10       1.17           95.90
## 13              Progesterona        10       1.17           97.07
## 14                  Positivo         9       1.05           98.12
## 15          Familia práctica         8       0.94           99.06
## 16                      Bajo         5       0.58           99.64
## 17                       FSH         1       0.12           99.76
## 18                    Fuerte         1       0.12           99.88
## 19                 Pediatría         1       0.12          100.00

##   num.y frequency percentage cumulative_perc
## 1     0       402      47.02           47.02
## 2     1       241      28.19           75.21
## 3  <NA>       150      17.54           92.75
## 4     2        32       3.74           96.49
## 5     4        20       2.34           98.83
## 6     3        10       1.17          100.00

##    icon frequency percentage cumulative_perc
## 1    32       308      36.02           36.02
## 2  <NA>       150      17.54           53.56
## 3    -1        85       9.94           63.50
## 4    25        82       9.59           73.09
## 5    -2        68       7.95           81.04
## 6    21        66       7.72           88.76
## 7    31        41       4.80           93.56
## 8    -3        29       3.39           96.95
## 9     1        17       1.99           98.94
## 10   24         9       1.05          100.00

##        color frequency percentage cumulative_perc
## 1     -65536       472      55.20           55.20
## 2       <NA>       150      17.54           72.74
## 3  -16711936        77       9.01           81.75
## 4         -1        66       7.72           89.47
## 5   -2601529        33       3.86           93.33
## 6  -16711681        20       2.34           95.67
## 7    -338673        11       1.29           96.96
## 8  -16776961        10       1.17           98.13
## 9     -65281        10       1.17           99.30
## 10      -256         6       0.70          100.00
## [1] "Variables processed: date, symptom_id, name.x, num.x, mode, type, layout, chart, category, id.x, datetime, value, value_id, name.y, num.y, icon, color"
describe(data)
## data 
## 
##  17  Variables      855  Observations
## --------------------------------------------------------------------------------
## date 
##        n  missing distinct 
##      723      132      635 
## 
## lowest : 2012-09-09 2013-05-17 2013-05-29 2013-05-31 2013-06-05
## highest: 2020-05-14 2020-05-15 2020-05-26 2020-06-10 2020-06-11
## --------------------------------------------------------------------------------
## symptom_id 
##        n  missing distinct 
##      837       18       28 
## 
## lowest : 0                                    0239f552-c6b3-42ff-8005-0d45ea1f8962 0fa4d6da-91de-4504-a578-4bcc75d525c8 158f47bc-b2c5-463e-bffe-59db9423fe00 2a50ec7a-7d5c-462a-8004-076e552e84ec
## highest: cc0cc290-cbb2-464f-8174-9a5bce0fe639 ea62cb53-18f0-4f27-a236-8bd695926a8b f93bc06f-1489-410b-a02b-d0dd05d6fce5 fc56b772-6b14-45f3-aaec-76efe14f401d fd03ae70-ad11-4b31-ada8-f33ada07f92f
## --------------------------------------------------------------------------------
## name.x 
##        n  missing distinct 
##      836       19       27 
## 
## lowest : Acné cíclico          Calambres abdominales Cervical apertura     Citas médicas         Día del ciclo        
## highest: Posición cervical     Prueba del embarazo   Relación sexual       Temperatura           Test de ovulación    
## --------------------------------------------------------------------------------
## num.x 
##        n  missing distinct 
##      836       19       27 
## 
## lowest : -8998 -8999 -9986 -9987 -9994, highest: 5     6     7     8     9    
## --------------------------------------------------------------------------------
## mode 
##        n  missing distinct 
##      836       19        2 
##                     
## Value         0    1
## Frequency   719  117
## Proportion 0.86 0.14
## --------------------------------------------------------------------------------
## type 
##        n  missing distinct 
##      836       19        9 
## 
## lowest : ° 1 2 4 5, highest: 5 6 7 8 9
##                                                                 
## Value          °     1     2     4     5     6     7     8     9
## Frequency     17   408    78   308     1     8     1     1    14
## Proportion 0.020 0.488 0.093 0.368 0.001 0.010 0.001 0.001 0.017
## --------------------------------------------------------------------------------
## layout 
##        n  missing distinct 
##      836       19       19 
## 
## lowest : -1                                   0                                    1                                    2                                    2a50ec7a-7d5c-462a-8004-076e552e84ec
## highest: 8a63e2b4-61d7-43af-904d-9eff6e93392a 9c86dea7-6a8e-401f-9692-90e6ee0d23d7 cc0cc290-cbb2-464f-8174-9a5bce0fe639 ea62cb53-18f0-4f27-a236-8bd695926a8b fd03ae70-ad11-4b31-ada8-f33ada07f92f
## --------------------------------------------------------------------------------
## chart 
##        n  missing distinct 
##      836       19       22 
## 
## lowest : -1                                   0                                    0fa4d6da-91de-4504-a578-4bcc75d525c8 1                                    158f47bc-b2c5-463e-bffe-59db9423fe00
## highest: Insomnio                             Manchado / Sangrado                  Náuseas / vomitos                    Pechos sensibles                     Posición cervical                   
## --------------------------------------------------------------------------------
## category 
##        n  missing distinct 
##      836       19       27 
## 
## lowest : 0                                    0239f552-c6b3-42ff-8005-0d45ea1f8962 10                                   16                                   17                                  
## highest: Moco cervical                        Ovulación prevista                   Peso                                 Prueba del embarazo                  Test de ovulación                   
## --------------------------------------------------------------------------------
## id.x 
##        n  missing distinct 
##      117      738      117 
## 
## lowest : 009f6884-11f7-4d4e-8b1b-05c809f9be12 0141878b-80d4-44dc-8964-46bd870e39db 0292b053-4f55-4f77-97dc-91f7a6dc2341 03fbc39f-b17f-41cd-8d09-c1fb7e0f5951 0b992fff-4835-41a7-8a20-0813ea811087
## highest: f15a167e-5390-403f-a5c2-adb996ddda16 f573ddc8-7ca7-41ab-989b-508b2c77e5da f5b93dce-1016-4acf-bd0b-c602f9cc54d1 f775a24e-e538-4808-b96e-29960b8cc32a fd2ed856-ce1a-48ef-b2aa-8f117fbe4f5a
## --------------------------------------------------------------------------------
## datetime 
##        n  missing distinct 
##      117      738      117 
## 
## lowest : 2013-06-04T09:50:00 2013-06-09T10:02:00 2013-06-10T06:50:00 2013-06-14T09:15:00 2013-06-27T09:07:00
## highest: 2018-01-05T07:35:00 2018-07-04T11:50:00 2018-08-08T07:18:00 2018-11-24T09:43:00 2019-01-05T09:47:00
## --------------------------------------------------------------------------------
## value 
##        n  missing distinct 
##      117      738       62 
## 
## lowest : 36600 36700 36800 36900 37000, highest: 78200 78300 78500 79000 79900
## --------------------------------------------------------------------------------
## value_id 
##        n  missing distinct 
##      705      150       25 
## 
## lowest : 1be07fc1-2b81-43ea-8aa7-a540251286f7 23d86cea-d536-4343-ab59-a1bb86aec86e 2644c28d-dd59-4e26-b2be-58fc32e1e2f9 26b80cf4-a9f2-463f-8fd8-9930a99aaa04 27223b7a-9667-4d59-b840-cd4e910541fd
## highest: be8dc4f2-ebe8-4703-a0c1-f15a2eac4564 c0e12f9a-ee6f-426a-be24-392a641f43cc cc56c587-77d5-489e-a650-f7814c6f30b0 ddc86eb2-9841-4d12-96ba-640b8888ce45 f170f52d-0251-42f9-a0c4-b93d037823ab
## --------------------------------------------------------------------------------
## name.y 
##        n  missing distinct 
##      705      150       18 
## 
## lowest : Bajo                 Citrato de clomifeno Familia práctica     FSH                  Fuerte              
## highest: Pediatría            Positivo             Progesterona         Protegidas           Sin protección      
## 
## Bajo (5, 0.007), Citrato de clomifeno (20, 0.028), Familia práctica (8, 0.011),
## FSH (1, 0.001), Fuerte (1, 0.001), hCG (10, 0.014), Intensa (29, 0.041),
## Laboratorio (10, 0.014), Ligera (85, 0.121), Medio (11, 0.016), Moderada (68,
## 0.096), Negativo (82, 0.116), Obstetricia y Ginecología (47, 0.067), Pediatría
## (1, 0.001), Positivo (9, 0.013), Progesterona (10, 0.014), Protegidas (33,
## 0.047), Sin protección (275, 0.390)
## --------------------------------------------------------------------------------
## num.y 
##        n  missing distinct 
##      705      150        5 
## 
## lowest : 0 1 2 3 4, highest: 0 1 2 3 4
##                                         
## Value          0     1     2     3     4
## Frequency    402   241    32    10    20
## Proportion 0.570 0.342 0.045 0.014 0.028
## --------------------------------------------------------------------------------
## icon 
##        n  missing distinct 
##      705      150        9 
## 
## lowest : -1 -2 -3 1  21, highest: 21 24 25 31 32
##                                                                 
## Value         -1    -2    -3     1    21    24    25    31    32
## Frequency     85    68    29    17    66     9    82    41   308
## Proportion 0.121 0.096 0.041 0.024 0.094 0.013 0.116 0.058 0.437
## --------------------------------------------------------------------------------
## color 
##        n  missing distinct 
##      705      150        9 
## 
## lowest : -1        -16711681 -16711936 -16776961 -256     
## highest: -256      -2601529  -338673   -65281    -65536   
##                                                                       
## Value             -1 -16711681 -16711936 -16776961      -256  -2601529
## Frequency         66        20        77        10         6        33
## Proportion     0.094     0.028     0.109     0.014     0.009     0.047
##                                         
## Value        -338673    -65281    -65536
## Frequency         11        10       472
## Proportion     0.016     0.014     0.670
## --------------------------------------------------------------------------------
dim(data)
## [1] 855  17
summary(data)
##      date            symptom_id           name.x             num.x          
##  Length:855         Length:855         Length:855         Length:855        
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##      mode               type              layout             chart          
##  Length:855         Length:855         Length:855         Length:855        
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##    category             id.x             datetime            value          
##  Length:855         Length:855         Length:855         Length:855        
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##    value_id            name.y             num.y               icon          
##  Length:855         Length:855         Length:855         Length:855        
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##     color          
##  Length:855        
##  Class :character  
##  Mode  :character
colnames(data)
##  [1] "date"       "symptom_id" "name.x"     "num.x"      "mode"      
##  [6] "type"       "layout"     "chart"      "category"   "id.x"      
## [11] "datetime"   "value"      "value_id"   "name.y"     "num.y"     
## [16] "icon"       "color"

Obtenemos la fecha de datatime

data$Date <- lubridate::as_datetime(data$datetime)
data$date_ymd <- str_split_fixed(data$Date, " ", 2)

Si en date es NA, copia el campo de date_ymd

data$date <- ifelse(is.na(data$date), data$date_ymd, data$date)

Selecciono varias columnas

data <- select(data, -symptom_id, -value_id, -datetime, -value_id, -Date,  -date_ymd)
print("Mostrar variables con datos vacios")
## [1] "Mostrar variables con datos vacios"
colSums(data=="")
##     date   name.x    num.x     mode     type   layout    chart category 
##       15       NA       NA       NA       NA       NA       NA       NA 
##     id.x    value   name.y    num.y     icon    color 
##       NA       NA       NA       NA       NA       NA

Eliminar filas con campos vacios y na

datos <- data[-which(data$date==""),]
df <- datos[!is.na(datos$name.x), ]
df$name.y[is.na(df$name.y)] <- "desconocido"
df[is.na(df)] <- 0
datos <- select(df, -layout, -chart, -category, -id.x, -value)
print("Suma valores na")
## [1] "Suma valores na"
sum(is.na(datos))
## [1] 0
print("Mostrar variables con campos na")
## [1] "Mostrar variables con campos na"
colSums(is.na(datos))
##   date name.x  num.x   mode   type name.y  num.y   icon  color 
##      0      0      0      0      0      0      0      0      0
df <- select(datos, -num.x, -mode, -num.y )
rm(data, data_raw, datos)
df$date <- as.Date(df$date)
cols<-c("name.x","type","color","name.y", "icon")
for (i in cols){
  df[,i] <- as.factor(df[,i])
}
# ¿Con qué variables tendría sentido un proceso de discretización?
apply(df,2, function(x) length(unique(x)))
##   date name.x   type name.y   icon  color 
##    679     13      6     19     10     10
colnames(df) <- c("date","categ_1", "categ_2", "categ_3", "categ_4", "categ_5")
textscatter <- function(df, mapping, ...) {
   ggplot(df, mapping, ...) + geom_text()
}
library(GGally)
ggpairs(
  df, 
  title="Scatterplot de Variables",
  columns = c(2,3,5,6),
  mapping=ggplot2::aes(colour = categ_1))

  lower = list(continuous = textscatter)
skimr::skim(df)
Data summary
Name df
Number of rows 822
Number of columns 6
_______________________
Column type frequency:
Date 1
factor 5
________________________
Group variables None

Variable type: Date

skim_variable n_missing complete_rate min max median n_unique
date 0 1 2012-09-09 2020-06-11 2016-01-18 679

Variable type: factor

skim_variable n_missing complete_rate ordered n_unique top_counts
categ_1 0 1 FALSE 13 Rel: 308, Men: 182, Pes: 100, Tes: 77
categ_2 0 1 FALSE 6 1: 399, 4: 308, 2: 77, °: 17
categ_3 0 1 FALSE 19 Sin: 275, des: 117, Lig: 85, Neg: 82
categ_4 0 1 FALSE 10 32: 308, 0: 117, -1: 85, 25: 82
categ_5 0 1 FALSE 10 -65: 472, 0: 117, -16: 77, -1: 66
list(df$categ_1[1:2])
## [[1]]
## [1] Menstruación  Citas médicas
## 13 Levels: Citas médicas Dolor muscular / articular ... Test de ovulación
str(df$categ_1)
##  Factor w/ 13 levels "Citas médicas",..: 6 1 11 1 11 11 1 11 1 11 ...
levels(df$categ_1)
##  [1] "Citas médicas"              "Dolor muscular / articular"
##  [3] "Dolores de cabeza"          "Manchado / Sangrado"       
##  [5] "Medicamentos"               "Menstruación"              
##  [7] "Náuseas / vomitos"          "Pechos sensibles"          
##  [9] "Peso"                       "Prueba del embarazo"       
## [11] "Relación sexual"            "Temperatura"               
## [13] "Test de ovulación"
summary(df$categ_1)
##              Citas médicas Dolor muscular / articular 
##                         66                          1 
##          Dolores de cabeza        Manchado / Sangrado 
##                          7                          1 
##               Medicamentos               Menstruación 
##                         41                        182 
##          Náuseas / vomitos           Pechos sensibles 
##                          4                          4 
##                       Peso        Prueba del embarazo 
##                        100                         14 
##            Relación sexual                Temperatura 
##                        308                         17 
##          Test de ovulación 
##                         77

4.1 .- Otro Resumen dataframe

aed_basico <- function(data)
{
  glimpse(data)
  status(data) #library(git2r)
  freq(data) 
  # profiling_num(data)
  plot_num(data)
  describe(data)
  dim(data)
  summary(data)
  colnames(data)
  str(data)
}
aed_basico((df))
## Rows: 822
## Columns: 6
## $ date    <date> 2012-09-09, 2013-05-17, 2013-05-29, 2013-05-31, 2013-06-05, …
## $ categ_1 <fct> Menstruación, Citas médicas, Relación sexual, Citas médicas, …
## $ categ_2 <fct> 1, 1, 4, 1, 4, 4, 1, 4, 1, 4, 4, 1, 4, 4, 1, 1, 1, 1, 1, 4, 4…
## $ categ_3 <fct> Moderada, Obstetricia y Ginecología, Sin protección, Obstetri…
## $ categ_4 <fct> -2, 21, 32, 21, 32, 32, 21, 32, 21, 32, 32, -1, 32, 32, -2, -…
## $ categ_5 <fct> -65536, -1, -65536, -1, -65536, -65536, -1, -65536, -1, -2601…

##                       categ_1 frequency percentage cumulative_perc
## 1             Relación sexual       308      37.47           37.47
## 2                Menstruación       182      22.14           59.61
## 3                        Peso       100      12.17           71.78
## 4           Test de ovulación        77       9.37           81.15
## 5               Citas médicas        66       8.03           89.18
## 6                Medicamentos        41       4.99           94.17
## 7                 Temperatura        17       2.07           96.24
## 8         Prueba del embarazo        14       1.70           97.94
## 9           Dolores de cabeza         7       0.85           98.79
## 10          Náuseas / vomitos         4       0.49           99.28
## 11           Pechos sensibles         4       0.49           99.77
## 12 Dolor muscular / articular         1       0.12           99.89
## 13        Manchado / Sangrado         1       0.12          100.00

##   categ_2 frequency percentage cumulative_perc
## 1       1       399      48.54           48.54
## 2       4       308      37.47           86.01
## 3       2        77       9.37           95.38
## 4       °        17       2.07           97.45
## 5       9        14       1.70           99.15
## 6       6         7       0.85          100.00

##                      categ_3 frequency percentage cumulative_perc
## 1             Sin protección       275      33.45           33.45
## 2                desconocido       117      14.23           47.68
## 3                     Ligera        85      10.34           58.02
## 4                   Negativo        82       9.98           68.00
## 5                   Moderada        68       8.27           76.27
## 6  Obstetricia y Ginecología        47       5.72           81.99
## 7                 Protegidas        33       4.01           86.00
## 8                    Intensa        29       3.53           89.53
## 9       Citrato de clomifeno        20       2.43           91.96
## 10                     Medio        11       1.34           93.30
## 11                       hCG        10       1.22           94.52
## 12               Laboratorio        10       1.22           95.74
## 13              Progesterona        10       1.22           96.96
## 14                  Positivo         9       1.09           98.05
## 15          Familia práctica         8       0.97           99.02
## 16                      Bajo         5       0.61           99.63
## 17                       FSH         1       0.12           99.75
## 18                    Fuerte         1       0.12           99.87
## 19                 Pediatría         1       0.12          100.00

##    categ_4 frequency percentage cumulative_perc
## 1       32       308      37.47           37.47
## 2        0       117      14.23           51.70
## 3       -1        85      10.34           62.04
## 4       25        82       9.98           72.02
## 5       -2        68       8.27           80.29
## 6       21        66       8.03           88.32
## 7       31        41       4.99           93.31
## 8       -3        29       3.53           96.84
## 9        1        17       2.07           98.91
## 10      24         9       1.09          100.00

##      categ_5 frequency percentage cumulative_perc
## 1     -65536       472      57.42           57.42
## 2          0       117      14.23           71.65
## 3  -16711936        77       9.37           81.02
## 4         -1        66       8.03           89.05
## 5   -2601529        33       4.01           93.06
## 6  -16711681        20       2.43           95.49
## 7    -338673        11       1.34           96.83
## 8  -16776961        10       1.22           98.05
## 9     -65281        10       1.22           99.27
## 10      -256         6       0.73          100.00

## 'data.frame':    822 obs. of  6 variables:
##  $ date   : Date, format: "2012-09-09" "2013-05-17" ...
##  $ categ_1: Factor w/ 13 levels "Citas médicas",..: 6 1 11 1 11 11 1 11 1 11 ...
##  $ categ_2: Factor w/ 6 levels "°","1","2","4",..: 2 2 4 2 4 4 2 4 2 4 ...
##  $ categ_3: Factor w/ 19 levels "Bajo","Citrato de clomifeno",..: 12 14 19 14 19 19 14 19 14 18 ...
##  $ categ_4: Factor w/ 10 levels "-1","-2","-3",..: 2 6 10 6 10 10 6 10 6 10 ...
##  $ categ_5: Factor w/ 10 levels "-1","-16711681",..: 9 1 9 1 9 9 1 9 1 6 ...
#library(epiDisplay)
epiDisplay::codebook(df[2:6])
## 
##  
##  
## categ_1   :    
##                            Frequency Percent
## Citas médicas                     66   8.029
## Dolor muscular / articular         1   0.122
## Dolores de cabeza                  7   0.852
## Manchado / Sangrado                1   0.122
## Medicamentos                      41   4.988
## Menstruación                     182  22.141
## Náuseas / vomitos                  4   0.487
## Pechos sensibles                   4   0.487
## Peso                             100  12.165
## Prueba del embarazo               14   1.703
## Relación sexual                  308  37.470
## Temperatura                       17   2.068
## Test de ovulación                 77   9.367
## 
##  ================== 
## categ_2   :    
##   Frequency Percent
## °        17   2.068
## 1       399  48.540
## 2        77   9.367
## 4       308  37.470
## 6         7   0.852
## 9        14   1.703
## 
##  ================== 
## categ_3   :    
##                           Frequency Percent
## Bajo                              5   0.608
## Citrato de clomifeno             20   2.433
## desconocido                     117  14.234
## Familia práctica                  8   0.973
## FSH                               1   0.122
## Fuerte                            1   0.122
## hCG                              10   1.217
## Intensa                          29   3.528
## Laboratorio                      10   1.217
## Ligera                           85  10.341
## Medio                            11   1.338
## Moderada                         68   8.273
## Negativo                         82   9.976
## Obstetricia y Ginecología        47   5.718
## Pediatría                         1   0.122
## Positivo                          9   1.095
## Progesterona                     10   1.217
## Protegidas                       33   4.015
## Sin protección                  275  33.455
## 
##  ================== 
## categ_4   :    
##    Frequency Percent
## -1        85   10.34
## -2        68    8.27
## -3        29    3.53
## 0        117   14.23
## 1         17    2.07
## 21        66    8.03
## 24         9    1.09
## 25        82    9.98
## 31        41    4.99
## 32       308   37.47
## 
##  ================== 
## categ_5   :    
##           Frequency Percent
## -1               66    8.03
## -16711681        20    2.43
## -16711936        77    9.37
## -16776961        10    1.22
## -256              6    0.73
## -2601529         33    4.01
## -338673          11    1.34
## -65281           10    1.22
## -65536          472   57.42
## 0               117   14.23
## 
##  ==================
epiDisplay::summ(df)
## 
## No. of observations = 822
## 
##   Var. name obs. mean          median  s.d.   min.   max.  
## 1 date      822  16953.2615572 16818.5 <NA>   15592  18424 
## 2 categ_1   822  8.617         10      3.379  1      13    
## 3 categ_2   822  2.916         2       1.06   1      6     
## 4 categ_3   822  12.762        13      5.912  1      19    
## 5 categ_4   822  6.6           8       3.365  1      10    
## 6 categ_5   822  7.518         9       2.917  1      10
visdat::vis_dat(df)

# creo una columna de unos
ones<- matrix(1, 822, 1)
df <- cbind(df,ones)
df$ones <- as.factor(df$ones)

4.2 .-Matrices

library(psych)
pairs.panels(df, pch=21,main="Matriz de Dispersión, Histograma y Correlación")

ts <- seq.POSIXt(as.POSIXct("2012-01-01",'%Y/%m/%d'), as.POSIXct("2020-06-20",'%Y/%m/%d'), by="day")

ts <- seq.POSIXt(as.POSIXlt("2012-01-01"), as.POSIXlt("2020-06-20"), by="day")
ts <- format.POSIXct(ts,'%Y/%m/%d')

dfa <- data.frame(timestamp=ts)
X <- matrix(0, 3093, 6)
ddfa <- cbind(dfa,X)
colnames(ddfa)<- c("date", "categ_1", "categ_2", "categ_3", "categ_4", "categ_5","ones")
ddfa <- as.data.frame(ddfa)
ddfa$date <- as.Date(ddfa$date)
# Sustituyo valores NA en 0
df$ones[is.na(df$ones)] <- 0
data <- full_join(ddfa,df) %>%
  group_by(date) #%>%
  #arrange(date())
# Elimino las tablas que no necesito
rm(ddfa, df,dfa,lower,X,ones)
ggplot( data = data, aes( date, categ_1 )) + geom_line() 

ggplot(data, aes(x=date, y=categ_1,color=categ_1)) + geom_line()

library(tidyr)
data_F <- spread(data, key = categ_1, value = ones)%>%
  select(-categ_3,-categ_4,-categ_5)%>%
  select("Menstruación","Pechos sensibles","Dolor muscular / articular","Dolores de cabeza", "Manchado / Sangrado")
colnames(data_F) <- c("fecha", "menstruacion", "p_sensible", "dolor_muscular", "dolor_cabeza", "manchado")
#data_F( ,[2:6])[is.na(data_F( ,[2:6]))] <- 0
data_F$menstruacion[is.na(data_F$menstruacion)] <- 0
data_F$p_sensible[is.na(data_F$p_sensible)] <- 0
data_F$dolor_muscular[is.na(data_F$dolor_muscular)] <- 0
data_F$dolor_cabeza[is.na(data_F$dolor_cabeza)] <- 0
data_F$manchado[is.na(data_F$manchado)] <- 0
#data_FF <- data_F%>%
#  group_by(fecha)%>%
#  summarise(menstruacion = sum(menstruacion),
#            p_sensible = sum(p_sensible),
#            dolor_muscular = sum(dolor_muscular),
#            dolor_cabeza = sum(dolor_cabeza))%>%
#  arrange(fecha)
colss <- c("menstruacion", "p_sensible", "dolor_muscular", "dolor_cabeza", "manchado")
for (i in colss){
  data_F[,i] <- as.numeric(unlist(data_F[,i]))
}
# sustituyo 1 por 0 y 2 por 1
data_F[data_F == 1] <- 0
data_F[data_F == 2] <- 1

data_F$fecha <- as.Date(data_F$fecha)

head(data_F)
## # A tibble: 6 x 6
## # Groups:   fecha [6]
##   fecha      menstruacion p_sensible dolor_muscular dolor_cabeza manchado
##   <date>            <dbl>      <dbl>          <dbl>        <dbl>    <dbl>
## 1 2012-01-01            0          0              0            0        0
## 2 2012-01-02            0          0              0            0        0
## 3 2012-01-03            0          0              0            0        0
## 4 2012-01-04            0          0              0            0        0
## 5 2012-01-05            0          0              0            0        0
## 6 2012-01-06            0          0              0            0        0
data_F_mens=0
data_F_mens$difere=0
data_F_mens <- data_F %>%
  select(fecha,menstruacion)%>%
    group_by(fecha) %>%
  filter(menstruacion == 1)%>%
  arrange(fecha)
data_F_mens$difere=0
for (i in 2:nrow(data_F_mens)) {
  data_F_mens$difere[i] <- difftime(data_F_mens$fecha[i], data_F_mens$fecha[i-1], units = "days")
}
dataFmen <- data_F_mens %>%
  dplyr::mutate(dates2=dmy(fecha),
                year = lubridate::year(fecha), 
                month = lubridate::month(fecha), 
                day = lubridate::day(fecha))
dataFmen$date <-paste(dataFmen$month, dataFmen$year, sep="-")
dataFmen$dmy <- paste(dataFmen$year,dataFmen$month, dataFmen$day, sep="-")
#dataFmen$dia <- paste(dateFmen$day, dataFmen$month, dataFmen$year, sep = "-")
dataFmen$date
##   [1] "9-2012"  "7-2013"  "8-2013"  "8-2013"  "8-2013"  "8-2013"  "8-2013" 
##   [8] "9-2013"  "9-2013"  "9-2013"  "9-2013"  "7-2014"  "8-2014"  "8-2014" 
##  [15] "8-2014"  "9-2014"  "9-2014"  "9-2014"  "9-2014"  "10-2014" "10-2014"
##  [22] "10-2014" "10-2014" "12-2014" "12-2014" "12-2014" "12-2014" "12-2014"
##  [29] "12-2014" "12-2014" "12-2014" "12-2014" "12-2014" "2-2015"  "2-2015" 
##  [36] "2-2015"  "2-2015"  "2-2015"  "3-2015"  "3-2015"  "3-2015"  "3-2015" 
##  [43] "3-2015"  "4-2015"  "4-2015"  "4-2015"  "4-2015"  "5-2015"  "7-2015" 
##  [50] "7-2015"  "7-2015"  "7-2015"  "7-2015"  "7-2015"  "7-2015"  "9-2015" 
##  [57] "9-2015"  "9-2015"  "9-2015"  "9-2015"  "9-2015"  "12-2015" "12-2015"
##  [64] "12-2015" "12-2015" "12-2015" "1-2016"  "1-2016"  "1-2016"  "1-2016" 
##  [71] "2-2016"  "2-2016"  "2-2016"  "2-2016"  "5-2016"  "5-2016"  "5-2016" 
##  [78] "5-2016"  "2-2017"  "3-2017"  "3-2017"  "3-2017"  "3-2017"  "3-2017" 
##  [85] "3-2017"  "4-2017"  "12-2017" "12-2017" "12-2017" "12-2017" "12-2017"
##  [92] "12-2017" "12-2017" "12-2017" "12-2017" "2-2018"  "2-2018"  "2-2018" 
##  [99] "3-2018"  "3-2018"  "3-2018"  "3-2018"  "3-2018"  "4-2018"  "4-2018" 
## [106] "4-2018"  "4-2018"  "4-2018"  "5-2018"  "5-2018"  "5-2018"  "5-2018" 
## [113] "6-2018"  "6-2018"  "7-2018"  "7-2018"  "8-2018"  "8-2018"  "9-2018" 
## [120] "9-2018"  "10-2018" "10-2018" "10-2018" "11-2018" "11-2018" "11-2018"
## [127] "11-2018" "12-2018" "1-2019"  "1-2019"  "1-2019"  "1-2019"  "1-2019" 
## [134] "2-2019"  "2-2019"  "2-2019"  "2-2019"  "2-2019"  "2-2019"  "2-2019" 
## [141] "3-2019"  "4-2019"  "4-2019"  "4-2019"  "4-2019"  "5-2019"  "5-2019" 
## [148] "6-2019"  "6-2019"  "6-2019"  "6-2019"  "6-2019"  "7-2019"  "7-2019" 
## [155] "7-2019"  "7-2019"  "7-2019"  "7-2019"  "8-2019"  "8-2019"  "9-2019" 
## [162] "9-2019"  "10-2019" "11-2019" "11-2019" "11-2019" "11-2019" "11-2019"
## [169] "12-2019" "1-2020"  "1-2020"  "1-2020"  "1-2020"  "2-2020"  "2-2020" 
## [176] "3-2020"  "5-2020"  "5-2020"  "5-2020"  "5-2020"  "6-2020"  "6-2020"
dataFmen$dmy <- as.Date(dataFmen$dmy)
DF <- dataFmen%>%
  dplyr::select(difere)
data_F_mensual <- dataFmen %>% 
  select(date,difere)%>%
  group_by(date)%>%
  summarise(dias=sum(difere))

data_F_mensual$date <- str_pad(data_F_mensual$date,width = 7, side="left", pad = "0")


library(zoo)
data_F_mensual$date <- zoo::as.yearmon(data_F_mensual$date, format = "%m-%Y")

data_F_mensual %>%
  arrange(date)
## # A tibble: 51 x 2
##    date       dias
##    <yearmon> <dbl>
##  1 sep 2012      0
##  2 jul 2013    319
##  3 ago 2013     25
##  4 sep 2013     30
##  5 jul 2014    286
##  6 ago 2014     36
##  7 sep 2014     38
##  8 oct 2014     33
##  9 dic 2014     58
## 10 feb 2015     55
## # … with 41 more rows
rm(data, data_F, data_F_mens,dataFmen)
ts <- seq.POSIXt(as.POSIXct("2012-01-01",'%Y/%m/%d'),
                 as.POSIXct("2020-07-01",'%Y/%m/%d'), by="month")

ts <- seq.POSIXt(as.POSIXlt("2012-01-01"), as.POSIXlt("2020-07-01"), by="month")
ts <- format.POSIXct(ts,'%Y/%m/%d')

dfa <- data.frame(timestamp=ts)


zero<- matrix(1, 103, 1)

df <- cbind(dfa,zero)
rm(dfa)
df$zero[df$zero == 1] <- 0

dataF <- df %>%
  dplyr::mutate(year = lubridate::year(timestamp), 
                month = lubridate::month(timestamp), 
                day = lubridate::day(timestamp))
dataF$date <-paste(dataF$month, dataF$year, sep="-")

data_F_mensual_cero <- dataF %>% 
  select(date,zero)%>%
  group_by(date)%>%
  summarise(dias=sum(zero))

data_F_mensual_cero$date <- str_pad(data_F_mensual_cero$date,width = 7, side="left", pad = "0")


library(zoo)
data_F_mensual_cero$date <- zoo::as.yearmon(data_F_mensual_cero$date, format = "%m-%Y")

data_F_mensual_cero %>%
  arrange(date)
## # A tibble: 103 x 2
##    date       dias
##    <yearmon> <dbl>
##  1 ene 2012      0
##  2 feb 2012      0
##  3 mar 2012      0
##  4 abr 2012      0
##  5 may 2012      0
##  6 jun 2012      0
##  7 jul 2012      0
##  8 ago 2012      0
##  9 sep 2012      0
## 10 oct 2012      0
## # … with 93 more rows
rm(dataF,df,dfa)

data_F_mensual$dias[data_F_mensual$dias == 0] <- 28

datos <- rbind(data_F_mensual,data_F_mensual_cero) %>%
  arrange(date)
DATO <- datos%>%
  group_by(date)%>%
  summarise(valor=sum(dias))%>%
  select(date,valor)
rm(data_F_mensual,data_F_mensual_cero,datos)
df <- DATO %>% 
  dplyr::mutate(year = lubridate::year(date), 
                month = lubridate::month(date))%>%
  arrange(month)
df$month <- str_pad(df$month, width = 2, side="left", pad = "0")
df$month2 <- str_sub(df$date,1,3)
library(tidyquant)
df %>%
  ggplot(aes(x = df$month, y = valor, group = year)) +
  xlab(df$month2) +
  geom_area(aes(fill = year), position = "stack") +
  labs(title = "Grafica por mes/año", x = "mes", y = "valor",
      subtitle = "Valores por mes y año") +
  scale_y_continuous() +
  theme_tq()

DATO$fecha <- as.character(DATO$date)
DATO %<>% 
  tidyr::separate(fecha, into = c("m", "y"), sep = " ") %>%
  dplyr::mutate(y = as.numeric(y),
                m = match(m, month.abb),
                fechas = lubridate::make_date(y,m)) %>%
  dplyr::select(-m, -y)

5 .- Time-Series

pas1.ts <- ts(DATO["valor"], start = c(2012, 1), frequency = 12)
str(pas1.ts)
##  Time-Series [1:103, 1] from 2012 to 2020: 0 0 0 0 0 0 0 0 28 0 ...
##  - attr(*, "dimnames")=List of 2
##   ..$ : NULL
##   ..$ : chr "valor"
pas1.ts
##      Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
## 2012   0   0   0   0   0   0   0   0  28   0   0   0
## 2013   0   0   0   0   0   0 319  25  30   0   0   0
## 2014   0   0   0   0   0   0 286  36  38  33   0  58
## 2015   0  55  33  34  47   0  57   0  62   0   0  77
## 2016  34  29   0   0  81   0   0   0   0   0   0   0
## 2017   0 275  50   9   0   0   0   0   0   0   0 268
## 2018   0  45  29  30  37  39  32  34  30   3  34  29
## 2019  34  31  28  38  27  39  34  27  31  32  32  27
## 2020  40  28  28   0  51  27   0
autoplot(pas1.ts)

autoplot(pas1.ts, ts.colour = "red", ts.linetype = "dashed")

autoplot(pacf(pas1.ts, plot = FALSE))

autoplot(acf(pas1.ts, plot = FALSE), conf.int.fill = "#0000FF", conf.int.value = 0.8,conf.int.type = "ma")

autoplot(spec.ar(pas1.ts, plot = FALSE))

library(ggfortify)
#library(zoo)
library(forecast)
ggtsdiag(auto.arima(pas1.ts))

gglagplot(pas1.ts, lags = 4)

ggfreqplot(pas1.ts)

ggfreqplot(pas1.ts, freq = 4)

arima1<-forecast::auto.arima(pas1.ts)
forecast1<-forecast::forecast(arima1,level = c(95), h = 50)
autoplot(forecast1)

autoplot(forecast1, ts.colour = "firebrick1", predict.colour = "red",
         predict.linetype = "dashed", conf.int = FALSE)

forecast::ggseasonplot(pas1.ts, year.labels=TRUE, year.labels.left=TRUE)

forecast::ggseasonplot(pas1.ts, year.labels=TRUE, year.labels.left=TRUE, polar = TRUE)

## .- Ruido Gaussiano linealmente dependiente en el tiempo

alpha <- 1
beta <- 0.1
t <- 1:103
mu <- alpha + beta*t

fit <- lm(pas1.ts ~ t)     #calcula la regresión  lm=modelo lineal
summary(fit)    #slow y el interceptro   y=ax+b
## 
## Call:
## lm(formula = pas1.ts ~ t)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -36.055 -25.167 -19.804   4.652 296.596 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)  
## (Intercept)  19.3170    11.1874   1.727   0.0873 .
## t             0.1625     0.1868   0.870   0.3863  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 56.36 on 101 degrees of freedom
## Multiple R-squared:  0.007439,   Adjusted R-squared:  -0.002388 
## F-statistic: 0.757 on 1 and 101 DF,  p-value: 0.3863
plot(fit)

dplyr::tibble(time = t, value = pas1.ts) %>%
  ggplot2::ggplot(ggplot2::aes(x = time, y = value)) +
  ggplot2::geom_line() +
  ggplot2::geom_abline(intercept = fit$coefficients[1], slope = fit$coefficients[2], col = "red")   #quiero calcular la lina roja con una regresión

# SOI= LA SERIE TEMPORAL

soi.lag6 <- xts::lag.xts(pas1.ts,6)  # desplazar una serie temporal 6 veces, con lo que x1 es igual a y7, x2 igual a y8, x3 igual a y9....
fit <- lm(pas1.ts ~ soi.lag6)    # esta es la relación que hace
summary(fit)
## 
## Call:
## lm(formula = pas1.ts ~ soi.lag6)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -33.005 -33.005  -4.005   5.004 285.995 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  33.0046     6.4887   5.087 1.83e-06 ***
## soi.lag6     -0.1253     0.1013  -1.236    0.219    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 57.42 on 95 degrees of freedom
##   (6 observations deleted due to missingness)
## Multiple R-squared:  0.01583,    Adjusted R-squared:  0.005469 
## F-statistic: 1.528 on 1 and 95 DF,  p-value: 0.2195
dplyr::tibble(time = zoo::index(pas1.ts), 
              actual = zoo::coredata(pas1.ts),
              estimated = c(rep(0,6),fit$fitted.values)) %>%
  tidyr::gather(pas1.ts, Value, -time) %>%
  ggplot2::ggplot(ggplot2::aes(x = time, y = Value, col = pas1.ts)) +
  ggplot2::geom_line()

plot(fit)

# library(reshape2)
meltdf <- reshape2::melt(DATO,id="date")
ggplot(meltdf,aes(x=date,y=value,colour=variable,group=variable)) + geom_line()

## .- tslm rewritten

# autoplot of a forecast object
fc <- forecast::forecast(pas1.ts)
autoplot(fc)

# Plotting the components of an ETS model
fit <- forecast::ets(pas1.ts)
autoplot(fit)

# Plotting the inverse characteristic roots of an ARIMA model
fit <- forecast::auto.arima(pas1.ts, D=1)
autoplot(fit)

ggtsdisplay(pas1.ts)

ggseasonplot(pas1.ts)

menst.lm  <- tslm(pas1.ts ~ trend + fourier(pas1.ts,3))
menst.fcast <- forecast(menst.lm,
    data.frame(fourier(pas1.ts,3,36)))
autoplot(menst.fcast)

# camio los nombres de las columnas
names(DF)<-c("ds","y")
# sustituyo los valores 1 por 0
DF$y[DF$y == 1] <- 0
# incluyo un valor
DATO <-DF%>%
  mutate(y = replace(y, ds=="2012-09-09", 29))

DATO <-DATO%>%
  mutate(y = replace(y, ds=="2020-06-11", 29))

DATO <-DATO%>%
  mutate(ds = replace(ds, ds=="2020-06-11", "2020-07-10"))
  
DF <- DATO %>%
  filter(y>10)
summary(DF)
##        ds                   y         
##  Min.   :2012-09-09   Min.   : 22.00  
##  1st Qu.:2015-06-12   1st Qu.: 28.00  
##  Median :2018-04-26   Median : 31.00  
##  Mean   :2017-07-15   Mean   : 54.98  
##  3rd Qu.:2019-06-07   3rd Qu.: 44.50  
##  Max.   :2020-07-10   Max.   :319.00
# Calculo la moda
modeest::mfv(DF$y)
## [1] 29
m= prophet::prophet(DF)
m
## $growth
## [1] "linear"
## 
## $changepoints
##  [1] "2013-08-16 GMT" "2013-09-15 GMT" "2014-08-04 GMT" "2014-09-07 GMT"
##  [5] "2014-12-07 GMT" "2015-02-02 GMT" "2015-04-11 GMT" "2015-05-31 GMT"
##  [9] "2015-09-22 GMT" "2016-01-13 GMT" "2016-02-11 GMT" "2017-02-04 GMT"
## [13] "2017-03-21 GMT" "2018-02-09 GMT" "2018-03-08 GMT" "2018-05-15 GMT"
## [17] "2018-07-27 GMT" "2018-08-30 GMT" "2018-11-03 GMT" "2018-12-05 GMT"
## [21] "2019-02-02 GMT" "2019-03-08 GMT" "2019-05-11 GMT" "2019-06-16 GMT"
## [25] "2019-08-19 GMT"
## 
## $n.changepoints
## [1] 25
## 
## $changepoint.range
## [1] 0.8
## 
## $yearly.seasonality
## [1] "auto"
## 
## $weekly.seasonality
## [1] "auto"
## 
## $daily.seasonality
## [1] "auto"
## 
## $holidays
## NULL
## 
## $seasonality.mode
## [1] "additive"
## 
## $seasonality.prior.scale
## [1] 10
## 
## $changepoint.prior.scale
## [1] 0.05
## 
## $holidays.prior.scale
## [1] 10
## 
## $mcmc.samples
## [1] 0
## 
## $interval.width
## [1] 0.8
## 
## $uncertainty.samples
## [1] 1000
## 
## $specified.changepoints
## [1] FALSE
## 
## $start
## [1] "2012-09-09 GMT"
## 
## $y.scale
## [1] 319
## 
## $logistic.floor
## [1] FALSE
## 
## $t.scale
## [1] 247190400
## 
## $changepoints.t
##  [1] 0.1191891 0.1296749 0.2425725 0.2544565 0.2862635 0.3061866 0.3299546
##  [8] 0.3474310 0.3872772 0.4267739 0.4369102 0.5623908 0.5781195 0.6917162
## [15] 0.7011534 0.7249214 0.7504369 0.7623209 0.7850402 0.7962251 0.8168473
## [22] 0.8287312 0.8511010 0.8636840 0.8860538
## 
## $seasonalities
## $seasonalities$yearly
## $seasonalities$yearly$period
## [1] 365.25
## 
## $seasonalities$yearly$fourier.order
## [1] 10
## 
## $seasonalities$yearly$prior.scale
## [1] 10
## 
## $seasonalities$yearly$mode
## [1] "additive"
## 
## $seasonalities$yearly$condition.name
## NULL
## 
## 
## 
## $extra_regressors
## list()
## 
## $country_holidays
## NULL
## 
## $stan.fit
## $stan.fit$par
## $stan.fit$par$k
## [1] -0.3001667
## 
## $stan.fit$par$m
## [1] 0.3472811
## 
## $stan.fit$par$delta
##  [1] -9.224371e-11  2.274530e-12  2.632662e-11 -6.417207e-11 -1.274390e-10
##  [6]  1.328929e-10 -1.365647e-10  1.210806e-10  1.108463e-10  7.263403e-11
## [11] -5.459077e-11  1.126657e-10 -1.509415e-10 -1.387073e-10  3.288326e-12
## [16] -1.749745e-10  7.133282e-11  6.990091e-11  1.685207e-10 -1.081890e-11
## [21] -9.322807e-12  5.220184e-11 -1.604976e-10  1.812375e-10 -9.186081e-11
## 
## $stan.fit$par$sigma_obs
## [1] 0.1736673
## 
## $stan.fit$par$beta
##  [1]  0.0106061277 -0.0006356418 -0.0184992633  0.0877641816 -0.0187050192
##  [6] -0.0348382686  0.0168865974  0.0504891367 -0.0348728971 -0.0161552510
## [11] -0.0145480467  0.0304467588 -0.0394029539 -0.0101391044 -0.0723931696
## [16]  0.0254689558 -0.0428961392  0.0034579209 -0.0406740145 -0.0162581920
## 
## 
## $stan.fit$value
## [1] 62.70506
## 
## $stan.fit$return_code
## [1] 0
## 
## $stan.fit$theta_tilde
##               k         m      delta[1]    delta[2]     delta[3]      delta[4]
## [1,] -0.3001667 0.3472811 -9.224371e-11 2.27453e-12 2.632662e-11 -6.417207e-11
##          delta[5]     delta[6]      delta[7]     delta[8]     delta[9]
## [1,] -1.27439e-10 1.328929e-10 -1.365647e-10 1.210806e-10 1.108463e-10
##         delta[10]     delta[11]    delta[12]     delta[13]     delta[14]
## [1,] 7.263403e-11 -5.459077e-11 1.126657e-10 -1.509415e-10 -1.387073e-10
##         delta[15]     delta[16]    delta[17]    delta[18]    delta[19]
## [1,] 3.288326e-12 -1.749745e-10 7.133282e-11 6.990091e-11 1.685207e-10
##         delta[20]     delta[21]    delta[22]     delta[23]    delta[24]
## [1,] -1.08189e-11 -9.322807e-12 5.220184e-11 -1.604976e-10 1.812375e-10
##          delta[25] sigma_obs    beta[1]       beta[2]     beta[3]    beta[4]
## [1,] -9.186081e-11 0.1736673 0.01060613 -0.0006356418 -0.01849926 0.08776418
##          beta[5]     beta[6]   beta[7]    beta[8]    beta[9]    beta[10]
## [1,] -0.01870502 -0.03483827 0.0168866 0.05048914 -0.0348729 -0.01615525
##         beta[11]   beta[12]    beta[13]   beta[14]    beta[15]   beta[16]
## [1,] -0.01454805 0.03044676 -0.03940295 -0.0101391 -0.07239317 0.02546896
##         beta[17]    beta[18]    beta[19]    beta[20]
## [1,] -0.04289614 0.003457921 -0.04067401 -0.01625819
## 
## 
## $params
## $params$k
## [1] -0.3001667
## 
## $params$m
## [1] 0.3472811
## 
## $params$delta
##               [,1]        [,2]         [,3]          [,4]         [,5]
## [1,] -9.224371e-11 2.27453e-12 2.632662e-11 -6.417207e-11 -1.27439e-10
##              [,6]          [,7]         [,8]         [,9]        [,10]
## [1,] 1.328929e-10 -1.365647e-10 1.210806e-10 1.108463e-10 7.263403e-11
##              [,11]        [,12]         [,13]         [,14]        [,15]
## [1,] -5.459077e-11 1.126657e-10 -1.509415e-10 -1.387073e-10 3.288326e-12
##              [,16]        [,17]        [,18]        [,19]        [,20]
## [1,] -1.749745e-10 7.133282e-11 6.990091e-11 1.685207e-10 -1.08189e-11
##              [,21]        [,22]         [,23]        [,24]         [,25]
## [1,] -9.322807e-12 5.220184e-11 -1.604976e-10 1.812375e-10 -9.186081e-11
## 
## $params$sigma_obs
## [1] 0.1736673
## 
## $params$beta
##            [,1]          [,2]        [,3]       [,4]        [,5]        [,6]
## [1,] 0.01060613 -0.0006356418 -0.01849926 0.08776418 -0.01870502 -0.03483827
##           [,7]       [,8]       [,9]       [,10]       [,11]      [,12]
## [1,] 0.0168866 0.05048914 -0.0348729 -0.01615525 -0.01454805 0.03044676
##            [,13]      [,14]       [,15]      [,16]       [,17]       [,18]
## [1,] -0.03940295 -0.0101391 -0.07239317 0.02546896 -0.04289614 0.003457921
##            [,19]       [,20]
## [1,] -0.04067401 -0.01625819
## 
## 
## $history
## # A tibble: 50 x 5
## # Groups:   ds [50]
##    ds                      y floor     t y_scaled
##    <dttm>              <dbl> <dbl> <dbl>    <dbl>
##  1 2012-09-09 00:00:00    29     0 0       0.0909
##  2 2013-07-25 00:00:00   319     0 0.111   1     
##  3 2013-08-16 00:00:00    22     0 0.119   0.0690
##  4 2013-09-15 00:00:00    27     0 0.130   0.0846
##  5 2014-07-01 00:00:00   286     0 0.231   0.897 
##  6 2014-08-04 00:00:00    34     0 0.243   0.107 
##  7 2014-09-07 00:00:00    32     0 0.254   0.100 
##  8 2014-10-13 00:00:00    30     0 0.267   0.0940
##  9 2014-12-07 00:00:00    52     0 0.286   0.163 
## 10 2015-02-02 00:00:00    51     0 0.306   0.160 
## # … with 40 more rows
## 
## $history.dates
##  [1] "2012-09-09 GMT" "2013-07-25 GMT" "2013-08-16 GMT" "2013-09-15 GMT"
##  [5] "2014-07-01 GMT" "2014-08-04 GMT" "2014-09-07 GMT" "2014-10-13 GMT"
##  [9] "2014-12-07 GMT" "2015-02-02 GMT" "2015-03-07 GMT" "2015-04-11 GMT"
## [13] "2015-05-31 GMT" "2015-07-21 GMT" "2015-09-22 GMT" "2015-12-09 GMT"
## [17] "2016-01-13 GMT" "2016-02-11 GMT" "2016-05-02 GMT" "2017-02-04 GMT"
## [21] "2017-03-21 GMT" "2017-12-20 GMT" "2018-02-09 GMT" "2018-03-08 GMT"
## [25] "2018-04-07 GMT" "2018-05-15 GMT" "2018-06-25 GMT" "2018-07-27 GMT"
## [29] "2018-08-30 GMT" "2018-09-30 GMT" "2018-11-03 GMT" "2018-12-05 GMT"
## [33] "2019-01-04 GMT" "2019-02-02 GMT" "2019-03-08 GMT" "2019-04-12 GMT"
## [37] "2019-05-11 GMT" "2019-06-16 GMT" "2019-07-19 GMT" "2019-08-19 GMT"
## [41] "2019-09-18 GMT" "2019-10-22 GMT" "2019-11-19 GMT" "2019-12-20 GMT"
## [45] "2020-01-26 GMT" "2020-02-25 GMT" "2020-03-25 GMT" "2020-05-12 GMT"
## [49] "2020-06-10 GMT" "2020-07-10 GMT"
## 
## $train.holiday.names
## NULL
## 
## $train.component.cols
##    additive_terms yearly multiplicative_terms
## 1               1      1                    0
## 2               1      1                    0
## 3               1      1                    0
## 4               1      1                    0
## 5               1      1                    0
## 6               1      1                    0
## 7               1      1                    0
## 8               1      1                    0
## 9               1      1                    0
## 10              1      1                    0
## 11              1      1                    0
## 12              1      1                    0
## 13              1      1                    0
## 14              1      1                    0
## 15              1      1                    0
## 16              1      1                    0
## 17              1      1                    0
## 18              1      1                    0
## 19              1      1                    0
## 20              1      1                    0
## 
## $component.modes
## $component.modes$additive
## [1] "yearly"                    "additive_terms"           
## [3] "extra_regressors_additive" "holidays"                 
## 
## $component.modes$multiplicative
## [1] "multiplicative_terms"            "extra_regressors_multiplicative"
## 
## 
## $fit.kwargs
## list()
## 
## attr(,"class")
## [1] "prophet" "list"
# creamos el data.frame de base para el forecast con la función, incluida en el paquete, llamada make_future_dataframe. Y finalmente, usando la función genérica predict calculamos nuestro forecast.
future_df_prophet <- prophet::make_future_dataframe(m, periods = 24, freq = "months")
forecast <- predict(m, future_df_prophet)
tail(forecast[c("ds", "yhat", "yhat_lower","yhat_upper")], 24) # muestra de las últimas 12 filas de las columnas 1 y 2
##            ds       yhat  yhat_lower yhat_upper
## 51 2020-08-10 -12.227503  -85.150147   57.16422
## 52 2020-09-10 -32.810440 -105.012328   35.01267
## 53 2020-10-10  -2.657905  -76.563221   65.70874
## 54 2020-11-10  43.776963  -25.047073  115.74442
## 55 2020-12-10  36.382154  -37.945767  105.65894
## 56 2021-01-10 -30.901199 -102.480771   41.17990
## 57 2021-02-10  27.063977  -46.473923   93.85795
## 58 2021-03-10  -4.891745  -74.167857   69.30898
## 59 2021-04-10 -11.157906  -83.142239   57.71789
## 60 2021-05-10  17.995534  -51.917425   87.89040
## 61 2021-06-10  -5.819857  -72.138489   66.88218
## 62 2021-07-10  66.046576   -3.712635  133.67362
## 63 2021-08-10 -23.775603 -103.011335   46.05325
## 64 2021-09-10 -44.978123 -114.551199   27.43736
## 65 2021-10-10 -14.252917  -83.374498   61.93984
## 66 2021-11-10  31.773528  -39.876193   98.57483
## 67 2021-12-10  21.473568  -51.736128   94.07679
## 68 2022-01-10 -42.053386 -112.913042   27.87176
## 69 2022-02-10  16.013125  -48.968938   91.09247
## 70 2022-03-10 -17.481512  -89.258617   53.33024
## 71 2022-04-10 -23.162400  -96.630333   38.02565
## 72 2022-05-10   5.681424  -64.904666   76.34818
## 73 2022-06-10 -19.462706  -93.846008   54.62235
## 74 2022-07-10  54.310739  -14.080568  125.46050
# vemos el resultado de la predicción.
plot(m ,forecast) 

prophet::prophet_plot_components(m ,forecast)

# Vemos la gráfica de forma interactiva
prophet::dyplot.prophet(m, forecast)

##############################333

6 Corregimos los datos

6.1 Sustituyo los valores outliers por la moda

# Sustituyo los valores superioes a 200 por la moda
#library(modeest)
modeest::mfv(DF$y)
## [1] 29
DF <- DF%>%
  mutate(y = replace(y, y>200, mfv(DF$y)))%>%
  filter(y<200 & y>1)
 #Indica el o los valores con más frecuencia
m= prophet::prophet(DF)
m
## $growth
## [1] "linear"
## 
## $changepoints
##  [1] "2013-08-16 GMT" "2013-09-15 GMT" "2014-08-04 GMT" "2014-09-07 GMT"
##  [5] "2014-12-07 GMT" "2015-02-02 GMT" "2015-04-11 GMT" "2015-05-31 GMT"
##  [9] "2015-09-22 GMT" "2016-01-13 GMT" "2016-02-11 GMT" "2017-02-04 GMT"
## [13] "2017-03-21 GMT" "2018-02-09 GMT" "2018-03-08 GMT" "2018-05-15 GMT"
## [17] "2018-07-27 GMT" "2018-08-30 GMT" "2018-11-03 GMT" "2018-12-05 GMT"
## [21] "2019-02-02 GMT" "2019-03-08 GMT" "2019-05-11 GMT" "2019-06-16 GMT"
## [25] "2019-08-19 GMT"
## 
## $n.changepoints
## [1] 25
## 
## $changepoint.range
## [1] 0.8
## 
## $yearly.seasonality
## [1] "auto"
## 
## $weekly.seasonality
## [1] "auto"
## 
## $daily.seasonality
## [1] "auto"
## 
## $holidays
## NULL
## 
## $seasonality.mode
## [1] "additive"
## 
## $seasonality.prior.scale
## [1] 10
## 
## $changepoint.prior.scale
## [1] 0.05
## 
## $holidays.prior.scale
## [1] 10
## 
## $mcmc.samples
## [1] 0
## 
## $interval.width
## [1] 0.8
## 
## $uncertainty.samples
## [1] 1000
## 
## $specified.changepoints
## [1] FALSE
## 
## $start
## [1] "2012-09-09 GMT"
## 
## $y.scale
## [1] 78
## 
## $logistic.floor
## [1] FALSE
## 
## $t.scale
## [1] 247190400
## 
## $changepoints.t
##  [1] 0.1191891 0.1296749 0.2425725 0.2544565 0.2862635 0.3061866 0.3299546
##  [8] 0.3474310 0.3872772 0.4267739 0.4369102 0.5623908 0.5781195 0.6917162
## [15] 0.7011534 0.7249214 0.7504369 0.7623209 0.7850402 0.7962251 0.8168473
## [22] 0.8287312 0.8511010 0.8636840 0.8860538
## 
## $seasonalities
## $seasonalities$yearly
## $seasonalities$yearly$period
## [1] 365.25
## 
## $seasonalities$yearly$fourier.order
## [1] 10
## 
## $seasonalities$yearly$prior.scale
## [1] 10
## 
## $seasonalities$yearly$mode
## [1] "additive"
## 
## $seasonalities$yearly$condition.name
## NULL
## 
## 
## 
## $extra_regressors
## list()
## 
## $country_holidays
## NULL
## 
## $stan.fit
## $stan.fit$par
## $stan.fit$par$k
## [1] -0.1586665
## 
## $stan.fit$par$m
## [1] 0.5416131
## 
## $stan.fit$par$delta
##  [1]  5.189815e-11  1.642905e-10 -1.698389e-10 -2.176398e-10  1.015737e-10
##  [6] -8.268038e-07 -1.168132e-10 -3.043822e-10 -6.179129e-05 -3.975575e-10
## [11] -1.563962e-10 -2.596810e-06  2.742583e-11 -6.374238e-07 -1.413782e-10
## [16] -2.802557e-11 -7.520774e-11  1.048699e-10  6.899028e-11  1.716658e-10
## [21] -1.044479e-10  1.375717e-10 -1.184922e-10 -2.339773e-11  1.582198e-10
## 
## $stan.fit$par$sigma_obs
## [1] 0.10544
## 
## $stan.fit$par$beta
##  [1]  0.054037318 -0.005424828 -0.076137909 -0.013143892 -0.007463079
##  [6]  0.039317801  0.033791431  0.002184018 -0.038691056 -0.056908927
## [11] -0.006738086  0.003246190  0.032695694 -0.022666099 -0.021358230
## [16] -0.071768080 -0.030394700  0.015716300  0.065283467 -0.011015172
## 
## 
## $stan.fit$value
## [1] 87.44482
## 
## $stan.fit$return_code
## [1] 0
## 
## $stan.fit$theta_tilde
##               k         m     delta[1]     delta[2]      delta[3]      delta[4]
## [1,] -0.1586665 0.5416131 5.189815e-11 1.642905e-10 -1.698389e-10 -2.176398e-10
##          delta[5]      delta[6]      delta[7]      delta[8]      delta[9]
## [1,] 1.015737e-10 -8.268038e-07 -1.168132e-10 -3.043822e-10 -6.179129e-05
##          delta[10]     delta[11]    delta[12]    delta[13]     delta[14]
## [1,] -3.975575e-10 -1.563962e-10 -2.59681e-06 2.742583e-11 -6.374238e-07
##          delta[15]     delta[16]     delta[17]    delta[18]    delta[19]
## [1,] -1.413782e-10 -2.802557e-11 -7.520774e-11 1.048699e-10 6.899028e-11
##         delta[20]     delta[21]    delta[22]     delta[23]     delta[24]
## [1,] 1.716658e-10 -1.044479e-10 1.375717e-10 -1.184922e-10 -2.339773e-11
##         delta[25] sigma_obs    beta[1]      beta[2]     beta[3]     beta[4]
## [1,] 1.582198e-10   0.10544 0.05403732 -0.005424828 -0.07613791 -0.01314389
##           beta[5]   beta[6]    beta[7]     beta[8]     beta[9]    beta[10]
## [1,] -0.007463079 0.0393178 0.03379143 0.002184018 -0.03869106 -0.05690893
##          beta[11]   beta[12]   beta[13]   beta[14]    beta[15]    beta[16]
## [1,] -0.006738086 0.00324619 0.03269569 -0.0226661 -0.02135823 -0.07176808
##        beta[17]  beta[18]   beta[19]    beta[20]
## [1,] -0.0303947 0.0157163 0.06528347 -0.01101517
## 
## 
## $params
## $params$k
## [1] -0.1586665
## 
## $params$m
## [1] 0.5416131
## 
## $params$delta
##              [,1]         [,2]          [,3]          [,4]         [,5]
## [1,] 5.189815e-11 1.642905e-10 -1.698389e-10 -2.176398e-10 1.015737e-10
##               [,6]          [,7]          [,8]          [,9]         [,10]
## [1,] -8.268038e-07 -1.168132e-10 -3.043822e-10 -6.179129e-05 -3.975575e-10
##              [,11]        [,12]        [,13]         [,14]         [,15]
## [1,] -1.563962e-10 -2.59681e-06 2.742583e-11 -6.374238e-07 -1.413782e-10
##              [,16]         [,17]        [,18]        [,19]        [,20]
## [1,] -2.802557e-11 -7.520774e-11 1.048699e-10 6.899028e-11 1.716658e-10
##              [,21]        [,22]         [,23]         [,24]        [,25]
## [1,] -1.044479e-10 1.375717e-10 -1.184922e-10 -2.339773e-11 1.582198e-10
## 
## $params$sigma_obs
## [1] 0.10544
## 
## $params$beta
##            [,1]         [,2]        [,3]        [,4]         [,5]      [,6]
## [1,] 0.05403732 -0.005424828 -0.07613791 -0.01314389 -0.007463079 0.0393178
##            [,7]        [,8]        [,9]       [,10]        [,11]      [,12]
## [1,] 0.03379143 0.002184018 -0.03869106 -0.05690893 -0.006738086 0.00324619
##           [,13]      [,14]       [,15]       [,16]      [,17]     [,18]
## [1,] 0.03269569 -0.0226661 -0.02135823 -0.07176808 -0.0303947 0.0157163
##           [,19]       [,20]
## [1,] 0.06528347 -0.01101517
## 
## 
## $history
## # A tibble: 50 x 5
## # Groups:   ds [50]
##    ds                      y floor     t y_scaled
##    <dttm>              <dbl> <dbl> <dbl>    <dbl>
##  1 2012-09-09 00:00:00    29     0 0        0.372
##  2 2013-07-25 00:00:00    29     0 0.111    0.372
##  3 2013-08-16 00:00:00    22     0 0.119    0.282
##  4 2013-09-15 00:00:00    27     0 0.130    0.346
##  5 2014-07-01 00:00:00    29     0 0.231    0.372
##  6 2014-08-04 00:00:00    34     0 0.243    0.436
##  7 2014-09-07 00:00:00    32     0 0.254    0.410
##  8 2014-10-13 00:00:00    30     0 0.267    0.385
##  9 2014-12-07 00:00:00    52     0 0.286    0.667
## 10 2015-02-02 00:00:00    51     0 0.306    0.654
## # … with 40 more rows
## 
## $history.dates
##  [1] "2012-09-09 GMT" "2013-07-25 GMT" "2013-08-16 GMT" "2013-09-15 GMT"
##  [5] "2014-07-01 GMT" "2014-08-04 GMT" "2014-09-07 GMT" "2014-10-13 GMT"
##  [9] "2014-12-07 GMT" "2015-02-02 GMT" "2015-03-07 GMT" "2015-04-11 GMT"
## [13] "2015-05-31 GMT" "2015-07-21 GMT" "2015-09-22 GMT" "2015-12-09 GMT"
## [17] "2016-01-13 GMT" "2016-02-11 GMT" "2016-05-02 GMT" "2017-02-04 GMT"
## [21] "2017-03-21 GMT" "2017-12-20 GMT" "2018-02-09 GMT" "2018-03-08 GMT"
## [25] "2018-04-07 GMT" "2018-05-15 GMT" "2018-06-25 GMT" "2018-07-27 GMT"
## [29] "2018-08-30 GMT" "2018-09-30 GMT" "2018-11-03 GMT" "2018-12-05 GMT"
## [33] "2019-01-04 GMT" "2019-02-02 GMT" "2019-03-08 GMT" "2019-04-12 GMT"
## [37] "2019-05-11 GMT" "2019-06-16 GMT" "2019-07-19 GMT" "2019-08-19 GMT"
## [41] "2019-09-18 GMT" "2019-10-22 GMT" "2019-11-19 GMT" "2019-12-20 GMT"
## [45] "2020-01-26 GMT" "2020-02-25 GMT" "2020-03-25 GMT" "2020-05-12 GMT"
## [49] "2020-06-10 GMT" "2020-07-10 GMT"
## 
## $train.holiday.names
## NULL
## 
## $train.component.cols
##    additive_terms yearly multiplicative_terms
## 1               1      1                    0
## 2               1      1                    0
## 3               1      1                    0
## 4               1      1                    0
## 5               1      1                    0
## 6               1      1                    0
## 7               1      1                    0
## 8               1      1                    0
## 9               1      1                    0
## 10              1      1                    0
## 11              1      1                    0
## 12              1      1                    0
## 13              1      1                    0
## 14              1      1                    0
## 15              1      1                    0
## 16              1      1                    0
## 17              1      1                    0
## 18              1      1                    0
## 19              1      1                    0
## 20              1      1                    0
## 
## $component.modes
## $component.modes$additive
## [1] "yearly"                    "additive_terms"           
## [3] "extra_regressors_additive" "holidays"                 
## 
## $component.modes$multiplicative
## [1] "multiplicative_terms"            "extra_regressors_multiplicative"
## 
## 
## $fit.kwargs
## list()
## 
## attr(,"class")
## [1] "prophet" "list"
# creamos el data.frame de base para el forecast con la función, incluida en el paquete, llamada make_future_dataframe. Y finalmente, usando la función genérica predict calculamos nuestro forecast.
future_df_prophet <- prophet::make_future_dataframe(m, periods = 24, freq = "months")
forecast <- predict(m, future_df_prophet)
tail(forecast[c("ds", "yhat", "yhat_lower","yhat_upper")], 24) # muestra de las últimas 12 filas de las columnas 1 y 2
##            ds     yhat yhat_lower yhat_upper
## 51 2020-08-10 19.48638   9.549298   30.88722
## 52 2020-09-10 22.86565  12.492999   33.61538
## 53 2020-10-10 23.13898  11.996523   34.63914
## 54 2020-11-10 24.43237  13.959990   35.05064
## 55 2020-12-10 42.14565  31.406383   53.10902
## 56 2021-01-10 26.30723  15.892670   37.03336
## 57 2021-02-10 27.50083  16.977758   38.43827
## 58 2021-03-10 26.59654  16.455268   37.46679
## 59 2021-04-10 25.71217  14.884137   36.14941
## 60 2021-05-10 43.00375  32.898733   53.36773
## 61 2021-06-10 36.31357  25.494012   47.65709
## 62 2021-07-10 30.89106  20.103845   41.32401
## 63 2021-08-10 17.80776   7.893730   28.11900
## 64 2021-09-10 21.07486  10.545432   31.10736
## 65 2021-10-10 21.63163  10.313179   31.48912
## 66 2021-11-10 23.01470  11.948248   33.83371
## 67 2021-12-10 40.75250  30.505222   51.18917
## 68 2022-01-10 24.51319  13.694734   35.18425
## 69 2022-02-10 26.04235  15.944304   36.68041
## 70 2022-03-10 24.76550  13.463140   35.12684
## 71 2022-04-10 23.72960  12.390996   33.88446
## 72 2022-05-10 42.17430  32.162158   52.70629
## 73 2022-06-10 34.81076  24.785612   45.39608
## 74 2022-07-10 29.11398  18.793087   39.58183
# vemos el resultado de la predicción.
plot(m ,forecast) 

prophet::prophet_plot_components(m ,forecast)

# Vemos la gráfica de forma interactiva
prophet::dyplot.prophet(m, forecast)

## Cubro el gap con la predicción del 2015

DF_1 <- DF%>%
  filter(ds>"2012-09-01" & ds<"2016-03-01")
m= prophet::prophet(DF_1)
m
## $growth
## [1] "linear"
## 
## $changepoints
##  [1] "2013-07-25 GMT" "2013-08-16 GMT" "2013-09-15 GMT" "2014-07-01 GMT"
##  [5] "2014-08-04 GMT" "2014-09-07 GMT" "2014-10-13 GMT" "2014-12-07 GMT"
##  [9] "2015-02-02 GMT" "2015-03-07 GMT" "2015-04-11 GMT" "2015-05-31 GMT"
## [13] "2015-07-21 GMT"
## 
## $n.changepoints
## [1] 13
## 
## $changepoint.range
## [1] 0.8
## 
## $yearly.seasonality
## [1] "auto"
## 
## $weekly.seasonality
## [1] "auto"
## 
## $daily.seasonality
## [1] "auto"
## 
## $holidays
## NULL
## 
## $seasonality.mode
## [1] "additive"
## 
## $seasonality.prior.scale
## [1] 10
## 
## $changepoint.prior.scale
## [1] 0.05
## 
## $holidays.prior.scale
## [1] 10
## 
## $mcmc.samples
## [1] 0
## 
## $interval.width
## [1] 0.8
## 
## $uncertainty.samples
## [1] 1000
## 
## $specified.changepoints
## [1] FALSE
## 
## $start
## [1] "2012-09-09 GMT"
## 
## $y.scale
## [1] 73
## 
## $logistic.floor
## [1] FALSE
## 
## $t.scale
## [1] 1.08e+08
## 
## $changepoints.t
##  [1] 0.2552 0.2728 0.2968 0.5280 0.5552 0.5824 0.6112 0.6552 0.7008 0.7272
## [11] 0.7552 0.7952 0.8360
## 
## $seasonalities
## $seasonalities$yearly
## $seasonalities$yearly$period
## [1] 365.25
## 
## $seasonalities$yearly$fourier.order
## [1] 10
## 
## $seasonalities$yearly$prior.scale
## [1] 10
## 
## $seasonalities$yearly$mode
## [1] "additive"
## 
## $seasonalities$yearly$condition.name
## NULL
## 
## 
## 
## $extra_regressors
## list()
## 
## $country_holidays
## NULL
## 
## $stan.fit
## $stan.fit$par
## $stan.fit$par$k
## [1] 0.09949978
## 
## $stan.fit$par$m
## [1] -0.9697463
## 
## $stan.fit$par$delta
##  [1] -4.890883e-02 -2.120526e-02 -6.466684e-02  1.697123e-07 -2.097848e-06
##  [6] -1.685613e-06 -6.520004e-07 -2.265817e-06 -2.965650e-06 -5.230879e-07
## [11] -6.806423e-07  5.191480e-07 -9.567068e-07
## 
## $stan.fit$par$sigma_obs
## [1] 2.870395e-10
## 
## $stan.fit$par$beta
##  [1] -2.07712374  2.08323364  2.42233885  2.71088275 -1.22720204  0.04487145
##  [7] -2.58599962  3.09476643  0.34124285  0.11436197 -1.26468885 -1.49571114
## [13]  0.11230855  2.09529414  1.39565415  0.64508014 -2.21436230  0.74609986
## [19] -0.88600130  1.84517305
## 
## 
## $stan.fit$value
## [1] 392.4702
## 
## $stan.fit$return_code
## [1] 0
## 
## $stan.fit$theta_tilde
##               k          m    delta[1]    delta[2]    delta[3]     delta[4]
## [1,] 0.09949978 -0.9697463 -0.04890883 -0.02120526 -0.06466684 1.697123e-07
##           delta[5]      delta[6]      delta[7]      delta[8]     delta[9]
## [1,] -2.097848e-06 -1.685613e-06 -6.520004e-07 -2.265817e-06 -2.96565e-06
##          delta[10]     delta[11]   delta[12]     delta[13]    sigma_obs
## [1,] -5.230879e-07 -6.806423e-07 5.19148e-07 -9.567068e-07 2.870395e-10
##        beta[1]  beta[2]  beta[3]  beta[4]   beta[5]    beta[6] beta[7]  beta[8]
## [1,] -2.077124 2.083234 2.422339 2.710883 -1.227202 0.04487145  -2.586 3.094766
##        beta[9] beta[10]  beta[11]  beta[12]  beta[13] beta[14] beta[15]
## [1,] 0.3412428 0.114362 -1.264689 -1.495711 0.1123086 2.095294 1.395654
##       beta[16]  beta[17]  beta[18]   beta[19] beta[20]
## [1,] 0.6450801 -2.214362 0.7460999 -0.8860013 1.845173
## 
## 
## $params
## $params$k
## [1] 0.09949978
## 
## $params$m
## [1] -0.9697463
## 
## $params$delta
##             [,1]        [,2]        [,3]         [,4]          [,5]
## [1,] -0.04890883 -0.02120526 -0.06466684 1.697123e-07 -2.097848e-06
##               [,6]          [,7]          [,8]         [,9]         [,10]
## [1,] -1.685613e-06 -6.520004e-07 -2.265817e-06 -2.96565e-06 -5.230879e-07
##              [,11]       [,12]         [,13]
## [1,] -6.806423e-07 5.19148e-07 -9.567068e-07
## 
## $params$sigma_obs
## [1] 2.870395e-10
## 
## $params$beta
##           [,1]     [,2]     [,3]     [,4]      [,5]       [,6]   [,7]     [,8]
## [1,] -2.077124 2.083234 2.422339 2.710883 -1.227202 0.04487145 -2.586 3.094766
##           [,9]    [,10]     [,11]     [,12]     [,13]    [,14]    [,15]
## [1,] 0.3412428 0.114362 -1.264689 -1.495711 0.1123086 2.095294 1.395654
##          [,16]     [,17]     [,18]      [,19]    [,20]
## [1,] 0.6450801 -2.214362 0.7460999 -0.8860013 1.845173
## 
## 
## $history
## # A tibble: 18 x 5
## # Groups:   ds [18]
##    ds                      y floor     t y_scaled
##    <dttm>              <dbl> <dbl> <dbl>    <dbl>
##  1 2012-09-09 00:00:00    29     0 0        0.397
##  2 2013-07-25 00:00:00    29     0 0.255    0.397
##  3 2013-08-16 00:00:00    22     0 0.273    0.301
##  4 2013-09-15 00:00:00    27     0 0.297    0.370
##  5 2014-07-01 00:00:00    29     0 0.528    0.397
##  6 2014-08-04 00:00:00    34     0 0.555    0.466
##  7 2014-09-07 00:00:00    32     0 0.582    0.438
##  8 2014-10-13 00:00:00    30     0 0.611    0.411
##  9 2014-12-07 00:00:00    52     0 0.655    0.712
## 10 2015-02-02 00:00:00    51     0 0.701    0.699
## 11 2015-03-07 00:00:00    29     0 0.727    0.397
## 12 2015-04-11 00:00:00    31     0 0.755    0.425
## 13 2015-05-31 00:00:00    47     0 0.795    0.644
## 14 2015-07-21 00:00:00    51     0 0.836    0.699
## 15 2015-09-22 00:00:00    57     0 0.886    0.781
## 16 2015-12-09 00:00:00    73     0 0.949    1    
## 17 2016-01-13 00:00:00    31     0 0.977    0.425
## 18 2016-02-11 00:00:00    26     0 1        0.356
## 
## $history.dates
##  [1] "2012-09-09 GMT" "2013-07-25 GMT" "2013-08-16 GMT" "2013-09-15 GMT"
##  [5] "2014-07-01 GMT" "2014-08-04 GMT" "2014-09-07 GMT" "2014-10-13 GMT"
##  [9] "2014-12-07 GMT" "2015-02-02 GMT" "2015-03-07 GMT" "2015-04-11 GMT"
## [13] "2015-05-31 GMT" "2015-07-21 GMT" "2015-09-22 GMT" "2015-12-09 GMT"
## [17] "2016-01-13 GMT" "2016-02-11 GMT"
## 
## $train.holiday.names
## NULL
## 
## $train.component.cols
##    additive_terms yearly multiplicative_terms
## 1               1      1                    0
## 2               1      1                    0
## 3               1      1                    0
## 4               1      1                    0
## 5               1      1                    0
## 6               1      1                    0
## 7               1      1                    0
## 8               1      1                    0
## 9               1      1                    0
## 10              1      1                    0
## 11              1      1                    0
## 12              1      1                    0
## 13              1      1                    0
## 14              1      1                    0
## 15              1      1                    0
## 16              1      1                    0
## 17              1      1                    0
## 18              1      1                    0
## 19              1      1                    0
## 20              1      1                    0
## 
## $component.modes
## $component.modes$additive
## [1] "yearly"                    "additive_terms"           
## [3] "extra_regressors_additive" "holidays"                 
## 
## $component.modes$multiplicative
## [1] "multiplicative_terms"            "extra_regressors_multiplicative"
## 
## 
## $fit.kwargs
## list()
## 
## attr(,"class")
## [1] "prophet" "list"
# creamos el data.frame de base para el forecast con la función, incluida en el paquete, llamada make_future_dataframe. Y finalmente, usando la función genérica predict calculamos nuestro forecast.
future_df_prophet <- prophet::make_future_dataframe(m, periods = 24, freq = "months")
forecast <- predict(m, future_df_prophet)
tail(forecast[c("ds", "yhat", "yhat_lower","yhat_upper")], 24) # muestra de las últimas 12 filas de las columnas 1 y 2
##            ds         yhat   yhat_lower   yhat_upper
## 19 2016-03-11    82.437579    82.434582    82.439125
## 20 2016-04-11    47.315828    47.297339    47.327989
## 21 2016-05-11 -1425.139648 -1425.180881 -1425.107253
## 22 2016-06-11    47.929116    47.860656    47.989790
## 23 2016-07-11   114.492289   114.395044   114.584873
## 24 2016-08-11    32.488693    32.353761    32.614490
## 25 2016-09-11    26.366816    26.188915    26.531004
## 26 2016-10-11    85.583929    85.362753    85.780383
## 27 2016-11-11  -193.371254  -193.641020  -193.128024
## 28 2016-12-11   151.372355   151.057078   151.671937
## 29 2017-01-11   110.945243   110.577156   111.299344
## 30 2017-02-11     7.956236     7.538959     8.363113
## 31 2017-03-11    81.498486    81.026799    81.960543
## 32 2017-04-11    41.217268    40.676637    41.728632
## 33 2017-05-11 -1432.847058 -1433.463189 -1432.264400
## 34 2017-06-11    53.171472    52.489683    53.810056
## 35 2017-07-11   114.336561   113.583046   115.041235
## 36 2017-08-11    32.214324    31.396219    32.969179
## 37 2017-09-11    25.908334    25.006696    26.738517
## 38 2017-10-11    93.233158    92.270183    94.133631
## 39 2017-11-11  -210.425132  -211.439218  -209.465744
## 40 2017-12-11   141.226056   140.152999   142.255295
## 41 2018-01-11   127.234829   126.094206   128.331294
## 42 2018-02-11    13.130628    11.913848    14.300373
# vemos el resultado de la predicción.
plot(m ,forecast) 

prophet::prophet_plot_components(m ,forecast)

# Vemos la gráfica de forma interactiva
prophet::dyplot.prophet(m, forecast)
# Genero un dataset
prev_1<- data.frame(forecast$ds,forecast$yhat)
colnames(prev_1)<- c("ds", "y")

add_gap <- prev_1 %>%
  dplyr::filter(ds>"2016-06-01" & ds<"2017-03-01")
DF_cumpli <- rbind(DF, add_gap)%>%
  arrange(ds)
m= prophet::prophet(DF_cumpli)
m
## $growth
## [1] "linear"
## 
## $changepoints
##  [1] "2013-08-16 GMT" "2014-07-01 GMT" "2014-09-07 GMT" "2014-10-13 GMT"
##  [5] "2015-02-02 GMT" "2015-04-11 GMT" "2015-07-21 GMT" "2015-12-09 GMT"
##  [9] "2016-02-11 GMT" "2016-05-02 GMT" "2016-07-11 GMT" "2016-09-11 GMT"
## [13] "2016-11-11 GMT" "2017-01-11 GMT" "2017-02-11 GMT" "2017-03-21 GMT"
## [17] "2018-02-09 GMT" "2018-04-07 GMT" "2018-06-25 GMT" "2018-08-30 GMT"
## [21] "2018-11-03 GMT" "2018-12-05 GMT" "2019-02-02 GMT" "2019-04-12 GMT"
## [25] "2019-06-16 GMT"
## 
## $n.changepoints
## [1] 25
## 
## $changepoint.range
## [1] 0.8
## 
## $yearly.seasonality
## [1] "auto"
## 
## $weekly.seasonality
## [1] "auto"
## 
## $daily.seasonality
## [1] "auto"
## 
## $holidays
## NULL
## 
## $seasonality.mode
## [1] "additive"
## 
## $seasonality.prior.scale
## [1] 10
## 
## $changepoint.prior.scale
## [1] 0.05
## 
## $holidays.prior.scale
## [1] 10
## 
## $mcmc.samples
## [1] 0
## 
## $interval.width
## [1] 0.8
## 
## $uncertainty.samples
## [1] 1000
## 
## $specified.changepoints
## [1] FALSE
## 
## $start
## [1] "2012-09-09 GMT"
## 
## $y.scale
## [1] 193.3713
## 
## $logistic.floor
## [1] FALSE
## 
## $t.scale
## [1] 247190400
## 
## $changepoints.t
##  [1] 0.1191891 0.2306886 0.2544565 0.2670395 0.3061866 0.3299546 0.3652569
##  [8] 0.4145404 0.4369102 0.4652220 0.4896889 0.5113597 0.5326809 0.5540021
## [15] 0.5648375 0.5781195 0.6917162 0.7116393 0.7392520 0.7623209 0.7850402
## [22] 0.7962251 0.8168473 0.8409647 0.8636840
## 
## $seasonalities
## $seasonalities$yearly
## $seasonalities$yearly$period
## [1] 365.25
## 
## $seasonalities$yearly$fourier.order
## [1] 10
## 
## $seasonalities$yearly$prior.scale
## [1] 10
## 
## $seasonalities$yearly$mode
## [1] "additive"
## 
## $seasonalities$yearly$condition.name
## NULL
## 
## 
## 
## $extra_regressors
## list()
## 
## $country_holidays
## NULL
## 
## $stan.fit
## $stan.fit$par
## $stan.fit$par$k
## [1] 0.002243471
## 
## $stan.fit$par$m
## [1] 0.173432
## 
## $stan.fit$par$delta
##  [1] -6.626886e-10 -7.779155e-10  3.478988e-11 -2.037687e-10  4.406802e-10
##  [6] -4.808166e-10  5.124068e-10 -5.557317e-10 -3.192337e-10 -3.875548e-10
## [11] -6.543476e-10  5.495209e-10  3.506575e-10  5.245850e-10 -5.265448e-10
## [16] -5.168352e-10  2.265928e-10 -3.202373e-10  5.692246e-10  3.585422e-10
## [21]  1.222611e-11 -2.734093e-10  4.446057e-10  1.297125e-10  1.886397e-10
## 
## $stan.fit$par$sigma_obs
## [1] 0.1457885
## 
## $stan.fit$par$beta
##  [1]  0.055532190 -0.034313373  0.021634502  0.024772392  0.030366055
##  [6]  0.074414758  0.014223712  0.081583565 -0.073725121  0.001700364
## [11] -0.044045617 -0.020153719  0.010026689 -0.073045681  0.046356193
## [16] -0.075961792  0.019716738 -0.007718628  0.062488096  0.023439161
## 
## 
## $stan.fit$value
## [1] 84.26407
## 
## $stan.fit$return_code
## [1] 0
## 
## $stan.fit$theta_tilde
##                k        m      delta[1]      delta[2]     delta[3]
## [1,] 0.002243471 0.173432 -6.626886e-10 -7.779155e-10 3.478988e-11
##           delta[4]     delta[5]      delta[6]     delta[7]      delta[8]
## [1,] -2.037687e-10 4.406802e-10 -4.808166e-10 5.124068e-10 -5.557317e-10
##           delta[9]     delta[10]     delta[11]    delta[12]    delta[13]
## [1,] -3.192337e-10 -3.875548e-10 -6.543476e-10 5.495209e-10 3.506575e-10
##        delta[14]     delta[15]     delta[16]    delta[17]     delta[18]
## [1,] 5.24585e-10 -5.265448e-10 -5.168352e-10 2.265928e-10 -3.202373e-10
##         delta[19]    delta[20]    delta[21]     delta[22]    delta[23]
## [1,] 5.692246e-10 3.585422e-10 1.222611e-11 -2.734093e-10 4.446057e-10
##         delta[24]    delta[25] sigma_obs    beta[1]     beta[2]   beta[3]
## [1,] 1.297125e-10 1.886397e-10 0.1457885 0.05553219 -0.03431337 0.0216345
##         beta[4]    beta[5]    beta[6]    beta[7]    beta[8]     beta[9]
## [1,] 0.02477239 0.03036606 0.07441476 0.01422371 0.08158356 -0.07372512
##         beta[10]    beta[11]    beta[12]   beta[13]    beta[14]   beta[15]
## [1,] 0.001700364 -0.04404562 -0.02015372 0.01002669 -0.07304568 0.04635619
##         beta[16]   beta[17]     beta[18]  beta[19]   beta[20]
## [1,] -0.07596179 0.01971674 -0.007718628 0.0624881 0.02343916
## 
## 
## $params
## $params$k
## [1] 0.002243471
## 
## $params$m
## [1] 0.173432
## 
## $params$delta
##               [,1]          [,2]         [,3]          [,4]         [,5]
## [1,] -6.626886e-10 -7.779155e-10 3.478988e-11 -2.037687e-10 4.406802e-10
##               [,6]         [,7]          [,8]          [,9]         [,10]
## [1,] -4.808166e-10 5.124068e-10 -5.557317e-10 -3.192337e-10 -3.875548e-10
##              [,11]        [,12]        [,13]       [,14]         [,15]
## [1,] -6.543476e-10 5.495209e-10 3.506575e-10 5.24585e-10 -5.265448e-10
##              [,16]        [,17]         [,18]        [,19]        [,20]
## [1,] -5.168352e-10 2.265928e-10 -3.202373e-10 5.692246e-10 3.585422e-10
##             [,21]         [,22]        [,23]        [,24]        [,25]
## [1,] 1.222611e-11 -2.734093e-10 4.446057e-10 1.297125e-10 1.886397e-10
## 
## $params$sigma_obs
## [1] 0.1457885
## 
## $params$beta
##            [,1]        [,2]      [,3]       [,4]       [,5]       [,6]
## [1,] 0.05553219 -0.03431337 0.0216345 0.02477239 0.03036606 0.07441476
##            [,7]       [,8]        [,9]       [,10]       [,11]       [,12]
## [1,] 0.01422371 0.08158356 -0.07372512 0.001700364 -0.04404562 -0.02015372
##           [,13]       [,14]      [,15]       [,16]      [,17]        [,18]
## [1,] 0.01002669 -0.07304568 0.04635619 -0.07596179 0.01971674 -0.007718628
##          [,19]      [,20]
## [1,] 0.0624881 0.02343916
## 
## 
## $history
## # A tibble: 59 x 5
## # Groups:   ds [59]
##    ds                      y floor     t y_scaled
##    <dttm>              <dbl> <dbl> <dbl>    <dbl>
##  1 2012-09-09 00:00:00    29     0 0        0.150
##  2 2013-07-25 00:00:00    29     0 0.111    0.150
##  3 2013-08-16 00:00:00    22     0 0.119    0.114
##  4 2013-09-15 00:00:00    27     0 0.130    0.140
##  5 2014-07-01 00:00:00    29     0 0.231    0.150
##  6 2014-08-04 00:00:00    34     0 0.243    0.176
##  7 2014-09-07 00:00:00    32     0 0.254    0.165
##  8 2014-10-13 00:00:00    30     0 0.267    0.155
##  9 2014-12-07 00:00:00    52     0 0.286    0.269
## 10 2015-02-02 00:00:00    51     0 0.306    0.264
## # … with 49 more rows
## 
## $history.dates
##  [1] "2012-09-09 GMT" "2013-07-25 GMT" "2013-08-16 GMT" "2013-09-15 GMT"
##  [5] "2014-07-01 GMT" "2014-08-04 GMT" "2014-09-07 GMT" "2014-10-13 GMT"
##  [9] "2014-12-07 GMT" "2015-02-02 GMT" "2015-03-07 GMT" "2015-04-11 GMT"
## [13] "2015-05-31 GMT" "2015-07-21 GMT" "2015-09-22 GMT" "2015-12-09 GMT"
## [17] "2016-01-13 GMT" "2016-02-11 GMT" "2016-05-02 GMT" "2016-06-11 GMT"
## [21] "2016-07-11 GMT" "2016-08-11 GMT" "2016-09-11 GMT" "2016-10-11 GMT"
## [25] "2016-11-11 GMT" "2016-12-11 GMT" "2017-01-11 GMT" "2017-02-04 GMT"
## [29] "2017-02-11 GMT" "2017-03-21 GMT" "2017-12-20 GMT" "2018-02-09 GMT"
## [33] "2018-03-08 GMT" "2018-04-07 GMT" "2018-05-15 GMT" "2018-06-25 GMT"
## [37] "2018-07-27 GMT" "2018-08-30 GMT" "2018-09-30 GMT" "2018-11-03 GMT"
## [41] "2018-12-05 GMT" "2019-01-04 GMT" "2019-02-02 GMT" "2019-03-08 GMT"
## [45] "2019-04-12 GMT" "2019-05-11 GMT" "2019-06-16 GMT" "2019-07-19 GMT"
## [49] "2019-08-19 GMT" "2019-09-18 GMT" "2019-10-22 GMT" "2019-11-19 GMT"
## [53] "2019-12-20 GMT" "2020-01-26 GMT" "2020-02-25 GMT" "2020-03-25 GMT"
## [57] "2020-05-12 GMT" "2020-06-10 GMT" "2020-07-10 GMT"
## 
## $train.holiday.names
## NULL
## 
## $train.component.cols
##    additive_terms yearly multiplicative_terms
## 1               1      1                    0
## 2               1      1                    0
## 3               1      1                    0
## 4               1      1                    0
## 5               1      1                    0
## 6               1      1                    0
## 7               1      1                    0
## 8               1      1                    0
## 9               1      1                    0
## 10              1      1                    0
## 11              1      1                    0
## 12              1      1                    0
## 13              1      1                    0
## 14              1      1                    0
## 15              1      1                    0
## 16              1      1                    0
## 17              1      1                    0
## 18              1      1                    0
## 19              1      1                    0
## 20              1      1                    0
## 
## $component.modes
## $component.modes$additive
## [1] "yearly"                    "additive_terms"           
## [3] "extra_regressors_additive" "holidays"                 
## 
## $component.modes$multiplicative
## [1] "multiplicative_terms"            "extra_regressors_multiplicative"
## 
## 
## $fit.kwargs
## list()
## 
## attr(,"class")
## [1] "prophet" "list"
# creamos el data.frame de base para el forecast con la función, incluida en el paquete, llamada make_future_dataframe. Y finalmente, usando la función genérica predict calculamos nuestro forecast.
future_df_prophet <- prophet::make_future_dataframe(m, periods = 24, freq = "months")
forecast <- predict(m, future_df_prophet)
tail(forecast[c("ds", "yhat", "yhat_lower","yhat_upper")], 24) # muestra de las últimas 12 filas de las columnas 1 y 2
##            ds      yhat  yhat_lower yhat_upper
## 60 2020-08-10  28.98846   -6.291166   66.68334
## 61 2020-09-10  31.22575   -2.699680   69.18458
## 62 2020-10-10  51.16474   15.292941   86.68893
## 63 2020-11-10 -79.41561 -115.013667  -40.59499
## 64 2020-12-10  76.40277   40.326971  111.28939
## 65 2021-01-10  60.97660   25.958135   98.48667
## 66 2021-02-10  27.15102   -7.380600   64.71864
## 67 2021-03-10  32.91059   -2.350243   69.28745
## 68 2021-04-10  31.15229   -4.657612   67.11866
## 69 2021-05-10  44.93744    8.344344   81.06986
## 70 2021-06-10  41.67889    6.252154   78.92739
## 71 2021-07-10  61.42710   24.300094   96.58942
## 72 2021-08-10  28.85057   -4.563035   65.08214
## 73 2021-09-10  30.97644   -5.715006   66.79780
## 74 2021-10-10  50.68771   15.134411   86.81083
## 75 2021-11-10 -78.72696 -113.943429  -43.30127
## 76 2021-12-10  77.02958   41.033820  114.25004
## 77 2022-01-10  60.50087   22.101943   98.77115
## 78 2022-02-10  27.28942   -9.194622   61.59336
## 79 2022-03-10  32.60746   -4.129208   68.61344
## 80 2022-04-10  30.49903   -7.246273   66.16567
## 81 2022-05-10  45.90372    8.982406   83.25703
## 82 2022-06-10  42.17661    5.751824   77.82341
## 83 2022-07-10  61.37132   24.558183   98.44782
# vemos el resultado de la predicción.
plot(m ,forecast) 

prophet::prophet_plot_components(m ,forecast)

# Vemos la gráfica de forma interactiva
prophet::dyplot.prophet(m, forecast)
DF_2 <- DF_cumpli%>%
  filter(ds>"2012-09-01" & ds<"2017-03-22")
m= prophet::prophet(DF_2)
m
## $growth
## [1] "linear"
## 
## $changepoints
##  [1] "2013-07-25 GMT" "2013-08-16 GMT" "2013-09-15 GMT" "2014-07-01 GMT"
##  [5] "2014-08-04 GMT" "2014-09-07 GMT" "2014-10-13 GMT" "2014-12-07 GMT"
##  [9] "2015-02-02 GMT" "2015-03-07 GMT" "2015-04-11 GMT" "2015-05-31 GMT"
## [13] "2015-07-21 GMT" "2015-09-22 GMT" "2015-12-09 GMT" "2016-01-13 GMT"
## [17] "2016-02-11 GMT" "2016-05-02 GMT" "2016-06-11 GMT" "2016-07-11 GMT"
## [21] "2016-08-11 GMT" "2016-09-11 GMT" "2016-10-11 GMT"
## 
## $n.changepoints
## [1] 23
## 
## $changepoint.range
## [1] 0.8
## 
## $yearly.seasonality
## [1] "auto"
## 
## $weekly.seasonality
## [1] "auto"
## 
## $daily.seasonality
## [1] "auto"
## 
## $holidays
## NULL
## 
## $seasonality.mode
## [1] "additive"
## 
## $seasonality.prior.scale
## [1] 10
## 
## $changepoint.prior.scale
## [1] 0.05
## 
## $holidays.prior.scale
## [1] 10
## 
## $mcmc.samples
## [1] 0
## 
## $interval.width
## [1] 0.8
## 
## $uncertainty.samples
## [1] 1000
## 
## $specified.changepoints
## [1] FALSE
## 
## $start
## [1] "2012-09-09 GMT"
## 
## $y.scale
## [1] 193.3713
## 
## $logistic.floor
## [1] FALSE
## 
## $t.scale
## [1] 142905600
## 
## $changepoints.t
##  [1] 0.1928658 0.2061669 0.2243047 0.3990326 0.4195889 0.4401451 0.4619105
##  [8] 0.4951632 0.5296252 0.5495768 0.5707376 0.6009674 0.6318017 0.6698912
## [15] 0.7170496 0.7382104 0.7557437 0.8047158 0.8288996 0.8470375 0.8657799
## [22] 0.8845224 0.9026602
## 
## $seasonalities
## $seasonalities$yearly
## $seasonalities$yearly$period
## [1] 365.25
## 
## $seasonalities$yearly$fourier.order
## [1] 10
## 
## $seasonalities$yearly$prior.scale
## [1] 10
## 
## $seasonalities$yearly$mode
## [1] "additive"
## 
## $seasonalities$yearly$condition.name
## NULL
## 
## 
## 
## $extra_regressors
## list()
## 
## $country_holidays
## NULL
## 
## $stan.fit
## $stan.fit$par
## $stan.fit$par$k
## [1] 0.0004989296
## 
## $stan.fit$par$m
## [1] 0.1356915
## 
## $stan.fit$par$delta
##  [1]  4.995401e-10 -5.766003e-10 -6.453863e-10  4.125884e-10  5.525516e-11
##  [6] -6.011933e-10 -5.542843e-10 -5.574334e-10 -2.101130e-04  3.681295e-10
## [11] -1.552185e-11 -1.122043e-04 -1.380503e-11 -5.570376e-10 -7.964334e-10
## [16] -7.191333e-10 -9.072058e-10 -7.605276e-10 -1.377170e-09 -9.682689e-10
## [21] -2.072642e-11  4.248666e-10 -9.026364e-10
## 
## $stan.fit$par$sigma_obs
## [1] 0.04421871
## 
## $stan.fit$par$beta
##  [1]  0.02259713  0.21335756  0.08451383  0.47899500 -0.33254056  0.68917428
##  [7] -0.32329225  0.67754520 -0.39357294 -0.03103581 -0.29998060  0.05874224
## [13]  0.26713793  0.31787736  0.05083243  0.05144021 -0.65142264  0.46669723
## [19] -0.10675885  0.52890228
## 
## 
## $stan.fit$value
## [1] 78.55072
## 
## $stan.fit$return_code
## [1] 0
## 
## $stan.fit$theta_tilde
##                 k         m     delta[1]      delta[2]      delta[3]
## [1,] 0.0004989296 0.1356915 4.995401e-10 -5.766003e-10 -6.453863e-10
##          delta[4]     delta[5]      delta[6]      delta[7]      delta[8]
## [1,] 4.125884e-10 5.525516e-11 -6.011933e-10 -5.542843e-10 -5.574334e-10
##          delta[9]    delta[10]     delta[11]     delta[12]     delta[13]
## [1,] -0.000210113 3.681295e-10 -1.552185e-11 -0.0001122043 -1.380503e-11
##          delta[14]     delta[15]     delta[16]     delta[17]     delta[18]
## [1,] -5.570376e-10 -7.964334e-10 -7.191333e-10 -9.072058e-10 -7.605276e-10
##         delta[19]     delta[20]     delta[21]    delta[22]     delta[23]
## [1,] -1.37717e-09 -9.682689e-10 -2.072642e-11 4.248666e-10 -9.026364e-10
##       sigma_obs    beta[1]   beta[2]    beta[3]  beta[4]    beta[5]   beta[6]
## [1,] 0.04421871 0.02259713 0.2133576 0.08451383 0.478995 -0.3325406 0.6891743
##         beta[7]   beta[8]    beta[9]    beta[10]   beta[11]   beta[12]
## [1,] -0.3232923 0.6775452 -0.3935729 -0.03103581 -0.2999806 0.05874224
##       beta[13]  beta[14]   beta[15]   beta[16]   beta[17]  beta[18]   beta[19]
## [1,] 0.2671379 0.3178774 0.05083243 0.05144021 -0.6514226 0.4666972 -0.1067588
##       beta[20]
## [1,] 0.5289023
## 
## 
## $params
## $params$k
## [1] 0.0004989296
## 
## $params$m
## [1] 0.1356915
## 
## $params$delta
##              [,1]          [,2]          [,3]         [,4]         [,5]
## [1,] 4.995401e-10 -5.766003e-10 -6.453863e-10 4.125884e-10 5.525516e-11
##               [,6]          [,7]          [,8]         [,9]        [,10]
## [1,] -6.011933e-10 -5.542843e-10 -5.574334e-10 -0.000210113 3.681295e-10
##              [,11]         [,12]         [,13]         [,14]         [,15]
## [1,] -1.552185e-11 -0.0001122043 -1.380503e-11 -5.570376e-10 -7.964334e-10
##              [,16]         [,17]         [,18]        [,19]         [,20]
## [1,] -7.191333e-10 -9.072058e-10 -7.605276e-10 -1.37717e-09 -9.682689e-10
##              [,21]        [,22]         [,23]
## [1,] -2.072642e-11 4.248666e-10 -9.026364e-10
## 
## $params$sigma_obs
## [1] 0.04421871
## 
## $params$beta
##            [,1]      [,2]       [,3]     [,4]       [,5]      [,6]       [,7]
## [1,] 0.02259713 0.2133576 0.08451383 0.478995 -0.3325406 0.6891743 -0.3232923
##           [,8]       [,9]       [,10]      [,11]      [,12]     [,13]     [,14]
## [1,] 0.6775452 -0.3935729 -0.03103581 -0.2999806 0.05874224 0.2671379 0.3178774
##           [,15]      [,16]      [,17]     [,18]      [,19]     [,20]
## [1,] 0.05083243 0.05144021 -0.6514226 0.4666972 -0.1067588 0.5289023
## 
## 
## $history
## # A tibble: 30 x 5
## # Groups:   ds [30]
##    ds                      y floor     t y_scaled
##    <dttm>              <dbl> <dbl> <dbl>    <dbl>
##  1 2012-09-09 00:00:00    29     0 0        0.150
##  2 2013-07-25 00:00:00    29     0 0.193    0.150
##  3 2013-08-16 00:00:00    22     0 0.206    0.114
##  4 2013-09-15 00:00:00    27     0 0.224    0.140
##  5 2014-07-01 00:00:00    29     0 0.399    0.150
##  6 2014-08-04 00:00:00    34     0 0.420    0.176
##  7 2014-09-07 00:00:00    32     0 0.440    0.165
##  8 2014-10-13 00:00:00    30     0 0.462    0.155
##  9 2014-12-07 00:00:00    52     0 0.495    0.269
## 10 2015-02-02 00:00:00    51     0 0.530    0.264
## # … with 20 more rows
## 
## $history.dates
##  [1] "2012-09-09 GMT" "2013-07-25 GMT" "2013-08-16 GMT" "2013-09-15 GMT"
##  [5] "2014-07-01 GMT" "2014-08-04 GMT" "2014-09-07 GMT" "2014-10-13 GMT"
##  [9] "2014-12-07 GMT" "2015-02-02 GMT" "2015-03-07 GMT" "2015-04-11 GMT"
## [13] "2015-05-31 GMT" "2015-07-21 GMT" "2015-09-22 GMT" "2015-12-09 GMT"
## [17] "2016-01-13 GMT" "2016-02-11 GMT" "2016-05-02 GMT" "2016-06-11 GMT"
## [21] "2016-07-11 GMT" "2016-08-11 GMT" "2016-09-11 GMT" "2016-10-11 GMT"
## [25] "2016-11-11 GMT" "2016-12-11 GMT" "2017-01-11 GMT" "2017-02-04 GMT"
## [29] "2017-02-11 GMT" "2017-03-21 GMT"
## 
## $train.holiday.names
## NULL
## 
## $train.component.cols
##    additive_terms yearly multiplicative_terms
## 1               1      1                    0
## 2               1      1                    0
## 3               1      1                    0
## 4               1      1                    0
## 5               1      1                    0
## 6               1      1                    0
## 7               1      1                    0
## 8               1      1                    0
## 9               1      1                    0
## 10              1      1                    0
## 11              1      1                    0
## 12              1      1                    0
## 13              1      1                    0
## 14              1      1                    0
## 15              1      1                    0
## 16              1      1                    0
## 17              1      1                    0
## 18              1      1                    0
## 19              1      1                    0
## 20              1      1                    0
## 
## $component.modes
## $component.modes$additive
## [1] "yearly"                    "additive_terms"           
## [3] "extra_regressors_additive" "holidays"                 
## 
## $component.modes$multiplicative
## [1] "multiplicative_terms"            "extra_regressors_multiplicative"
## 
## 
## $fit.kwargs
## list()
## 
## attr(,"class")
## [1] "prophet" "list"
# creamos el data.frame de base para el forecast con la función, incluida en el paquete, llamada make_future_dataframe. Y finalmente, usando la función genérica predict calculamos nuestro forecast.
future_df_prophet <- prophet::make_future_dataframe(m, periods = 24, freq = "months")
forecast <- predict(m, future_df_prophet)
tail(forecast[c("ds", "yhat", "yhat_lower","yhat_upper")], 24) # muestra de las últimas 12 filas de las columnas 1 y 2
##            ds       yhat yhat_lower yhat_upper
## 31 2017-04-21  403.30792  391.75389  413.73372
## 32 2017-05-21 -230.63348 -241.82102 -219.66729
## 33 2017-06-21  -42.84822  -53.84230  -31.38385
## 34 2017-07-21   54.67038   43.40812   65.45387
## 35 2017-08-21   22.20391   11.24206   32.91996
## 36 2017-09-21   53.45532   42.61872   64.10728
## 37 2017-10-21 -277.15863 -288.54733 -265.72059
## 38 2017-11-21  118.94677  108.73923  129.32450
## 39 2017-12-21  602.63903  591.88996  613.55340
## 40 2018-01-21 -209.18478 -220.08744 -198.34649
## 41 2018-02-21 -218.89401 -229.22165 -207.59393
## 42 2018-03-21   52.02913   40.74224   62.78733
## 43 2018-04-21  401.18588  390.82601  411.83413
## 44 2018-05-21 -237.86656 -248.66290 -226.27834
## 45 2018-06-21  -42.70666  -53.85921  -32.52039
## 46 2018-07-21   56.25263   46.21992   67.13284
## 47 2018-08-21   22.43700   11.34000   33.93788
## 48 2018-09-21   51.84868   40.47407   62.58102
## 49 2018-10-21 -266.84779 -277.97494 -255.85757
## 50 2018-11-21  115.84369  105.68905  127.74228
## 51 2018-12-21  591.39538  580.64154  603.19583
## 52 2019-01-21 -209.05615 -220.44573 -198.12786
## 53 2019-02-21 -215.95300 -225.99840 -204.87163
## 54 2019-03-21   59.69093   49.43177   70.82243
# vemos el resultado de la predicción.
plot(m ,forecast) 

prophet::prophet_plot_components(m ,forecast)

# Vemos la gráfica de forma interactiva
prophet::dyplot.prophet(m, forecast)
# Genero un dataset
prev_2<- data.frame(forecast$ds,forecast$yhat)
colnames(prev_2)<- c("ds", "y")

add_gap2 <- prev_2 %>%
  dplyr::filter(ds>"2017-03-02" & ds<"2017-12-01")
DF_cumplido <- rbind(DF_cumpli, add_gap2)%>%
  arrange(ds)
DF_cumplido <- data.frame(DF_cumplido)
boxplot(DF_cumplido$y)

# sustituimos los outliers por la media
mean(DF_cumplido$y)
## [1] 33.1606
# reemplazo de outliers con R
outliersReplace <- function(data, lowLimit, highLimit){
  data[data < lowLimit] <- mean(data)
  data[data > highLimit] <- median(data)
  data     #devolvemos el dato       
}
 
DF_cumplido$ys <- outliersReplace(DF_cumplido$y, 20, 60)
par(mfrow = c(1,2))
 
boxplot(DF_cumplido$y, main = "Sin reemplazo de outliers con R")
boxplot(DF_cumplido$ys, main = "Con reemplazo de outliers con R")

DF_cumplido <- DF_cumplido%>%
  select(ds,ys)

colnames(DF_cumplido) <- c("ds","y")
m= prophet::prophet(DF_cumplido)
m
## $growth
## [1] "linear"
## 
## $changepoints
##  [1] "2013-08-16 GMT" "2014-07-01 GMT" "2014-09-07 GMT" "2014-12-07 GMT"
##  [5] "2015-04-11 GMT" "2015-07-21 GMT" "2015-12-09 GMT" "2016-02-11 GMT"
##  [9] "2016-06-11 GMT" "2016-08-11 GMT" "2016-10-11 GMT" "2016-12-11 GMT"
## [13] "2017-02-11 GMT" "2017-03-21 GMT" "2017-05-21 GMT" "2017-07-21 GMT"
## [17] "2017-09-21 GMT" "2017-11-21 GMT" "2018-02-09 GMT" "2018-04-07 GMT"
## [21] "2018-07-27 GMT" "2018-09-30 GMT" "2018-12-05 GMT" "2019-02-02 GMT"
## [25] "2019-04-12 GMT"
## 
## $n.changepoints
## [1] 25
## 
## $changepoint.range
## [1] 0.8
## 
## $yearly.seasonality
## [1] "auto"
## 
## $weekly.seasonality
## [1] "auto"
## 
## $daily.seasonality
## [1] "auto"
## 
## $holidays
## NULL
## 
## $seasonality.mode
## [1] "additive"
## 
## $seasonality.prior.scale
## [1] 10
## 
## $changepoint.prior.scale
## [1] 0.05
## 
## $holidays.prior.scale
## [1] 10
## 
## $mcmc.samples
## [1] 0
## 
## $interval.width
## [1] 0.8
## 
## $uncertainty.samples
## [1] 1000
## 
## $specified.changepoints
## [1] FALSE
## 
## $start
## [1] "2012-09-09 GMT"
## 
## $y.scale
## [1] 57
## 
## $logistic.floor
## [1] FALSE
## 
## $t.scale
## [1] 247190400
## 
## $changepoints.t
##  [1] 0.1191891 0.2306886 0.2544565 0.2862635 0.3299546 0.3652569 0.4145404
##  [8] 0.4369102 0.4792031 0.5005243 0.5218455 0.5431667 0.5648375 0.5781195
## [15] 0.5994408 0.6207620 0.6424327 0.6637539 0.6917162 0.7116393 0.7504369
## [22] 0.7731562 0.7962251 0.8168473 0.8409647
## 
## $seasonalities
## $seasonalities$yearly
## $seasonalities$yearly$period
## [1] 365.25
## 
## $seasonalities$yearly$fourier.order
## [1] 10
## 
## $seasonalities$yearly$prior.scale
## [1] 10
## 
## $seasonalities$yearly$mode
## [1] "additive"
## 
## $seasonalities$yearly$condition.name
## NULL
## 
## 
## 
## $extra_regressors
## list()
## 
## $country_holidays
## NULL
## 
## $stan.fit
## $stan.fit$par
## $stan.fit$par$k
## [1] -0.1170377
## 
## $stan.fit$par$m
## [1] 0.6529306
## 
## $stan.fit$par$delta
##  [1] -8.438936e-11  6.705918e-11 -1.748139e-10  9.647235e-11 -1.028489e-07
##  [6] -7.455531e-11 -2.091698e-10 -2.633186e-10 -8.578937e-11 -4.563319e-11
## [11] -1.598237e-10 -3.807855e-10 -1.505891e-11  2.037823e-12 -4.228461e-08
## [16] -9.021332e-10 -5.124983e-10 -1.855701e-10 -2.030914e-10 -1.826039e-10
## [21] -1.582009e-10  5.939575e-11 -2.110264e-10  1.261452e-10 -1.137176e-10
## 
## $stan.fit$par$sigma_obs
## [1] 0.1209844
## 
## $stan.fit$par$beta
##  [1]  1.783405e-02 -1.829823e-02 -3.538345e-02  3.208659e-03  3.250552e-02
##  [6] -1.638247e-02  3.286684e-03  1.607049e-02 -9.799664e-03 -2.038322e-03
## [11]  4.552217e-02 -6.092417e-02 -7.290247e-03 -1.670439e-03 -2.402819e-02
## [16] -2.214170e-02 -9.990058e-03  8.592668e-05  3.267693e-02 -1.846748e-02
## 
## 
## $stan.fit$value
## [1] 109.5539
## 
## $stan.fit$return_code
## [1] 0
## 
## $stan.fit$theta_tilde
##               k         m      delta[1]     delta[2]      delta[3]     delta[4]
## [1,] -0.1170377 0.6529306 -8.438936e-11 6.705918e-11 -1.748139e-10 9.647235e-11
##           delta[5]      delta[6]      delta[7]      delta[8]      delta[9]
## [1,] -1.028489e-07 -7.455531e-11 -2.091698e-10 -2.633186e-10 -8.578937e-11
##          delta[10]     delta[11]     delta[12]     delta[13]    delta[14]
## [1,] -4.563319e-11 -1.598237e-10 -3.807855e-10 -1.505891e-11 2.037823e-12
##          delta[15]     delta[16]     delta[17]     delta[18]     delta[19]
## [1,] -4.228461e-08 -9.021332e-10 -5.124983e-10 -1.855701e-10 -2.030914e-10
##          delta[20]     delta[21]    delta[22]     delta[23]    delta[24]
## [1,] -1.826039e-10 -1.582009e-10 5.939575e-11 -2.110264e-10 1.261452e-10
##          delta[25] sigma_obs    beta[1]     beta[2]     beta[3]     beta[4]
## [1,] -1.137176e-10 0.1209844 0.01783405 -0.01829823 -0.03538345 0.003208659
##         beta[5]     beta[6]     beta[7]    beta[8]      beta[9]     beta[10]
## [1,] 0.03250552 -0.01638247 0.003286684 0.01607049 -0.009799664 -0.002038322
##        beta[11]    beta[12]     beta[13]     beta[14]    beta[15]   beta[16]
## [1,] 0.04552217 -0.06092417 -0.007290247 -0.001670439 -0.02402819 -0.0221417
##          beta[17]     beta[18]   beta[19]    beta[20]
## [1,] -0.009990058 8.592668e-05 0.03267693 -0.01846748
## 
## 
## $params
## $params$k
## [1] -0.1170377
## 
## $params$m
## [1] 0.6529306
## 
## $params$delta
##               [,1]         [,2]          [,3]         [,4]          [,5]
## [1,] -8.438936e-11 6.705918e-11 -1.748139e-10 9.647235e-11 -1.028489e-07
##               [,6]          [,7]          [,8]          [,9]         [,10]
## [1,] -7.455531e-11 -2.091698e-10 -2.633186e-10 -8.578937e-11 -4.563319e-11
##              [,11]         [,12]         [,13]        [,14]         [,15]
## [1,] -1.598237e-10 -3.807855e-10 -1.505891e-11 2.037823e-12 -4.228461e-08
##              [,16]         [,17]         [,18]         [,19]         [,20]
## [1,] -9.021332e-10 -5.124983e-10 -1.855701e-10 -2.030914e-10 -1.826039e-10
##              [,21]        [,22]         [,23]        [,24]         [,25]
## [1,] -1.582009e-10 5.939575e-11 -2.110264e-10 1.261452e-10 -1.137176e-10
## 
## $params$sigma_obs
## [1] 0.1209844
## 
## $params$beta
##            [,1]        [,2]        [,3]        [,4]       [,5]        [,6]
## [1,] 0.01783405 -0.01829823 -0.03538345 0.003208659 0.03250552 -0.01638247
##             [,7]       [,8]         [,9]        [,10]      [,11]       [,12]
## [1,] 0.003286684 0.01607049 -0.009799664 -0.002038322 0.04552217 -0.06092417
##             [,13]        [,14]       [,15]      [,16]        [,17]        [,18]
## [1,] -0.007290247 -0.001670439 -0.02402819 -0.0221417 -0.009990058 8.592668e-05
##           [,19]       [,20]
## [1,] 0.03267693 -0.01846748
## 
## 
## $history
##            ds        y floor         t  y_scaled
## 1  2012-09-09 29.00000     0 0.0000000 0.5087719
## 2  2013-07-25 29.00000     0 0.1114995 0.5087719
## 3  2013-08-16 22.00000     0 0.1191891 0.3859649
## 4  2013-09-15 27.00000     0 0.1296749 0.4736842
## 5  2014-07-01 29.00000     0 0.2306886 0.5087719
## 6  2014-08-04 34.00000     0 0.2425725 0.5964912
## 7  2014-09-07 32.00000     0 0.2544565 0.5614035
## 8  2014-10-13 30.00000     0 0.2670395 0.5263158
## 9  2014-12-07 52.00000     0 0.2862635 0.9122807
## 10 2015-02-02 51.00000     0 0.3061866 0.8947368
## 11 2015-03-07 29.00000     0 0.3177211 0.5087719
## 12 2015-04-11 31.00000     0 0.3299546 0.5438596
## 13 2015-05-31 47.00000     0 0.3474310 0.8245614
## 14 2015-07-21 51.00000     0 0.3652569 0.8947368
## 15 2015-09-22 57.00000     0 0.3872772 1.0000000
## 16 2015-12-09 32.00000     0 0.4145404 0.5614035
## 17 2016-01-13 31.00000     0 0.4267739 0.5438596
## 18 2016-02-11 26.00000     0 0.4369102 0.4561404
## 19 2016-05-02 32.00000     0 0.4652220 0.5614035
## 20 2016-06-11 47.92912     0 0.4792031 0.8408617
## 21 2016-07-11 32.00000     0 0.4896889 0.5614035
## 22 2016-08-11 32.48869     0 0.5005243 0.5699771
## 23 2016-09-11 26.36682     0 0.5113597 0.4625757
## 24 2016-10-11 32.00000     0 0.5218455 0.5614035
## 25 2016-11-11 33.16060     0 0.5326809 0.5817650
## 26 2016-12-11 32.00000     0 0.5431667 0.5614035
## 27 2017-01-11 32.00000     0 0.5540021 0.5614035
## 28 2017-02-04 29.00000     0 0.5623908 0.5087719
## 29 2017-02-11 33.16060     0 0.5648375 0.5817650
## 30 2017-03-21 45.00000     0 0.5781195 0.7894737
## 31 2017-03-21 44.21367     0 0.5781195 0.7756783
## 32 2017-04-21 32.00000     0 0.5889549 0.5614035
## 33 2017-05-21 33.16060     0 0.5994408 0.5817650
## 34 2017-06-21 33.16060     0 0.6102761 0.5817650
## 35 2017-07-21 54.67038     0 0.6207620 0.9591295
## 36 2017-08-21 22.20391     0 0.6315973 0.3895424
## 37 2017-09-21 53.45532     0 0.6424327 0.9378125
## 38 2017-10-21 33.16060     0 0.6529186 0.5817650
## 39 2017-11-21 32.00000     0 0.6637539 0.5614035
## 40 2017-12-20 29.00000     0 0.6738902 0.5087719
## 41 2018-02-09 43.00000     0 0.6917162 0.7543860
## 42 2018-03-08 25.00000     0 0.7011534 0.4385965
## 43 2018-04-07 26.00000     0 0.7116393 0.4561404
## 44 2018-05-15 34.00000     0 0.7249214 0.5964912
## 45 2018-06-25 38.00000     0 0.7392520 0.6666667
## 46 2018-07-27 31.00000     0 0.7504369 0.5438596
## 47 2018-08-30 33.00000     0 0.7623209 0.5789474
## 48 2018-09-30 29.00000     0 0.7731562 0.5087719
## 49 2018-11-03 31.00000     0 0.7850402 0.5438596
## 50 2018-12-05 29.00000     0 0.7962251 0.5087719
## 51 2019-01-04 30.00000     0 0.8067109 0.5263158
## 52 2019-02-02 25.00000     0 0.8168473 0.4385965
## 53 2019-03-08 28.00000     0 0.8287312 0.4912281
## 54 2019-04-12 35.00000     0 0.8409647 0.6140351
## 55 2019-05-11 26.00000     0 0.8511010 0.4561404
## 56 2019-06-16 35.00000     0 0.8636840 0.6140351
## 57 2019-07-19 29.00000     0 0.8752185 0.5087719
## 58 2019-08-19 26.00000     0 0.8860538 0.4561404
## 59 2019-09-18 29.00000     0 0.8965397 0.5087719
## 60 2019-10-22 32.00000     0 0.9084236 0.5614035
## 61 2019-11-19 28.00000     0 0.9182104 0.4912281
## 62 2019-12-20 27.00000     0 0.9290458 0.4736842
## 63 2020-01-26 37.00000     0 0.9419783 0.6491228
## 64 2020-02-25 27.00000     0 0.9524642 0.4736842
## 65 2020-03-25 28.00000     0 0.9626005 0.4912281
## 66 2020-05-12 48.00000     0 0.9793778 0.8421053
## 67 2020-06-10 26.00000     0 0.9895142 0.4561404
## 68 2020-07-10 29.00000     0 1.0000000 0.5087719
## 
## $history.dates
##  [1] "2012-09-09 GMT" "2013-07-25 GMT" "2013-08-16 GMT" "2013-09-15 GMT"
##  [5] "2014-07-01 GMT" "2014-08-04 GMT" "2014-09-07 GMT" "2014-10-13 GMT"
##  [9] "2014-12-07 GMT" "2015-02-02 GMT" "2015-03-07 GMT" "2015-04-11 GMT"
## [13] "2015-05-31 GMT" "2015-07-21 GMT" "2015-09-22 GMT" "2015-12-09 GMT"
## [17] "2016-01-13 GMT" "2016-02-11 GMT" "2016-05-02 GMT" "2016-06-11 GMT"
## [21] "2016-07-11 GMT" "2016-08-11 GMT" "2016-09-11 GMT" "2016-10-11 GMT"
## [25] "2016-11-11 GMT" "2016-12-11 GMT" "2017-01-11 GMT" "2017-02-04 GMT"
## [29] "2017-02-11 GMT" "2017-03-21 GMT" "2017-03-21 GMT" "2017-04-21 GMT"
## [33] "2017-05-21 GMT" "2017-06-21 GMT" "2017-07-21 GMT" "2017-08-21 GMT"
## [37] "2017-09-21 GMT" "2017-10-21 GMT" "2017-11-21 GMT" "2017-12-20 GMT"
## [41] "2018-02-09 GMT" "2018-03-08 GMT" "2018-04-07 GMT" "2018-05-15 GMT"
## [45] "2018-06-25 GMT" "2018-07-27 GMT" "2018-08-30 GMT" "2018-09-30 GMT"
## [49] "2018-11-03 GMT" "2018-12-05 GMT" "2019-01-04 GMT" "2019-02-02 GMT"
## [53] "2019-03-08 GMT" "2019-04-12 GMT" "2019-05-11 GMT" "2019-06-16 GMT"
## [57] "2019-07-19 GMT" "2019-08-19 GMT" "2019-09-18 GMT" "2019-10-22 GMT"
## [61] "2019-11-19 GMT" "2019-12-20 GMT" "2020-01-26 GMT" "2020-02-25 GMT"
## [65] "2020-03-25 GMT" "2020-05-12 GMT" "2020-06-10 GMT" "2020-07-10 GMT"
## 
## $train.holiday.names
## NULL
## 
## $train.component.cols
##    additive_terms yearly multiplicative_terms
## 1               1      1                    0
## 2               1      1                    0
## 3               1      1                    0
## 4               1      1                    0
## 5               1      1                    0
## 6               1      1                    0
## 7               1      1                    0
## 8               1      1                    0
## 9               1      1                    0
## 10              1      1                    0
## 11              1      1                    0
## 12              1      1                    0
## 13              1      1                    0
## 14              1      1                    0
## 15              1      1                    0
## 16              1      1                    0
## 17              1      1                    0
## 18              1      1                    0
## 19              1      1                    0
## 20              1      1                    0
## 
## $component.modes
## $component.modes$additive
## [1] "yearly"                    "additive_terms"           
## [3] "extra_regressors_additive" "holidays"                 
## 
## $component.modes$multiplicative
## [1] "multiplicative_terms"            "extra_regressors_multiplicative"
## 
## 
## $fit.kwargs
## list()
## 
## attr(,"class")
## [1] "prophet" "list"
# creamos el data.frame de base para el forecast con la función, incluida en el paquete, llamada make_future_dataframe. Y finalmente, usando la función genérica predict calculamos nuestro forecast.
future_df_prophet <- prophet::make_future_dataframe(m, periods =1, freq = "months")
forecast <- predict(m, future_df_prophet)
tail(forecast[c("ds", "yhat", "yhat_lower","yhat_upper")], 1) # muestra de las últimas 12 filas de las columnas 1 y 2
##            ds     yhat yhat_lower yhat_upper
## 69 2020-08-10 25.50266   17.10546   34.38513
# vemos el resultado de la predicción.
plot(m ,forecast) 

prophet::prophet_plot_components(m ,forecast)

# Vemos la gráfica de forma interactiva
prophet::dyplot.prophet(m, forecast)